There are much better and easier ways to test a read-only routing configuration of an Availability Group. But here is my walk-through using SQL Server Management Studio.
- In SSMS connect to “Database Engine”
- Type in the name of the listener, a comma, then the port used by the listener
- Click the “Options” button
- On the Connection Properties tab choose “Connect to Database” then “Browse Server”
- Choose a database protected by the AG
- On the Additional Parameters tab type “ApplicationIntent=ReadOnly”
- Click “Connect”
- Run a read-only query like “SELECT @@SERVERNAME”
- The result should be the Secondary instance (AKA secondary replica)
- Delete the query-pane and connection
- Then set it up again – but without “ApplicationIntent=ReadOnly”
- Now the result of the query should be the Primary replica.
The “much better ways” include using SQLCMD from another server. For example running this should return the name of the Secondary replica.
sqlcmd -S (ListenerName),(ListnerPort) -d (ProtectedDatabaseName) -q "SELECT @@SERVERNAME;" -K ReadOnly
Then, running it again without the last line should return the name of the Primary replica.
Note: It does not matter which Listener/Port you choose if there is more than one.