Skip to main content

Command Palette

Search for a command to run...

Quick Tip: Taking advantage of Read-Only SQL Server replicas in your C# application

Updated
1 min read
Quick Tip: Taking advantage of Read-Only SQL Server replicas in your C# application

If you happen to be using C# there is a very easy way to set your application up to take advantage of Read-Only replicas.

Using this connection string: (Some portions were left out for brevity)

"Server=tcp:<servername,port>;Initial Catalog=<database name>;ApplicationIntent=ReadOnly;"

The option ApplicationIntent=ReadOnly tells the system to first look for a replica when asking for a connection, but if there is no replica, then connect to the existing primary(read/write) server.

I have 2 connection strings in my APIs, one that includes that option and one that doesn't. This helps balance the calls between all the available backend resources without doing any special work within the calls themselves.

More from this blog

Untitled Publication

20 posts

I have over 34 years in the world of RDBMS. I have in-depth knowledge of Microsoft SQL Server and the Azure platform (Data Factories, Logic Apps, Functions, Event Grids).