SQL Server AG related question

Sam 1,476 Reputation points
2022-09-22T06:55:30.407+00:00

Hi All,

I have question on readonly routing.

We are trying to setup read only routing on AG. Reads are going to secondary but writes are also going to secondary and since secondary all dbs are in readonly mode , writes are failing. not sure if the routing tables is missing anything.

SQL Version

Microsoft SQL Server 2017 (RTM-CU30) (KB5013756) - 14.0.3451.2 (X64) Windows Server 2019 Datacenter 10.0 <X64> (Build 17763: ) (Hypervisor)

243749-2.png

243754-1.png

Regards,

Sam

SQL Server Other
0 comments No comments
{count} votes

Accepted answer
  1. Dan Guzman 9,401 Reputation points
    2022-09-22T13:33:48.717+00:00

    My question is, does the application team has to use 2 separate connection strings?

    Yes. The connection string should not specify read-only intent when writes are performed.

    For all this, I am assuming a lot of work needs to be done from application side?

    Not necessarily a lot of work, but much depends on application design. For example, if read-only reporting functionality is already segregated in the application code, I would expect the change to use a read-only connection string for report queries to be fairly trivial, especially if the code uses already a connection factory technique to centralize connection management.

    OTOH, if read and read-write functionality is co-mingled throughout a large app, there will be additional effort involved to leverage the secondary replica for the read-only workload. One migration strategy would be to change the connection string only for expensive read-only queries initially and follow up with others later. That way, the most costly readd-only queries won't impact the rest of the workload.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. YufeiShao-msft 7,146 Reputation points
    2022-09-22T07:42:51+00:00

    Hi @Sam

    You can refer to this official doc:
    Configure read-only routing for an Always On availability group

    You must configure one or more availability replicas to accept read-only in the secondary role ( to be readable secondary replicas)

    To support read-only routing, you must possess an availability group listener, read-only clients must direct their connection requests to this listener, and the client's connection strings must specify the application intent as "read-only", they must be read-intent connect requests

    In short, readable secondary replicas is required

    -------------

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    2 people found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.