Sql-server – SQL Server Connection property applicationIntent

availability-groupssql serversql-server-2016

I have a doubt in ApplicationIntent connection property of SQL Server.
The doc say it has two values ReadWrite and ReadOnly. If I set the value as ReadOnly, will it allow only read queries or will it also support update queries to SQLServer?


I am asking this ,keeping read only routing in AvailabilityGroups of SQLServer in mind!

Best Answer

Hopefully the documentation for the SQL Server Native Client clears things up for you, specifically this section on Specifying Application Intent

The keyword ApplicationIntent can be specified in your connection string. The assignable values are ReadWrite or ReadOnly. The default is ReadWrite.

When ApplicationIntent=ReadOnly, the client requests a read workload when connecting. The server enforces the intent at connection time, and during a USE database statement.

Since you mentioned that this is in the context of Availability Groups (AGs), specifying an intent of ReadOnly will connect you to the readable secondary in your availability group (as long as you are connect to the listener, and you're using Enterprise edition).

The enforcement, then, is due to the fact that the secondary is read-only - you can try to perform data modifications through this connect, but they will fail.

Note: for more complex setups, with multiple readable secondaries, you can Configure read-only routing as well