How to connect to secondary replica of SQL Server AlwaysOn Availability group
I have a problem with OLE DB connection which should be established to an SQL Server database which is a secondary replica in AlwayOn Availabilty group (AAG) and woring on read-only mode.
When connecting to the database the following error occurs:
SQL Server error: 978
The target database ('xxx') is in an availability group and is currently accessible for connections when the application intent is set to read only. For more information about application intent, see SQL Server Books Online.
I use the following OLE DB connection strings:
This one does work with the primary database - OLEDB CONNECT TO[Provider=SQLOLEDB.1;Initial Catalog=xxx;User ID=<USER NAME>;Database=xxx;Data Source=<PRIMARY SERVER NAME>];
This one does not work with the replica even if I add ApplicationIntent=ReadOnly - OLEDB CONNECT TO[Provider=SQLOLEDB.1;Initial Catalog=xxx;User ID=<USER NAME>;Database=xxx;ApplicationIntent=ReadOnly;Data Source=<SECONDARY SERVER NAME>];
Playing (adding and removing) with the following settings does not help as well:
Server=tcp:<PRIMARY OR SECONDARY SERVER NAME> (with the ports 1433 and 5022 and without them)