2 Replies Latest reply: May 18, 2016 3:07 AM by Maxim Senin RSS

    How to connect to secondary replica of SQL Server AlwaysOn Availability group

    Maxim Senin

      Hi everyone,


      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:


      SQLState: "42000"

      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)
      • IntegratedSecurity=SSPI
      • Database=xxx


      I googled a number of resources including

      but nothing helps. I'm stuck.


      Did anyone tried working with a read-only replica in AAG?


      Best regards,