Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Read-Only Access for Crystal Report in AlwaysOn environment

I have two SQL servers that are being load balanced - AlwaysOn. Only the second one of these servers is supposed to be used for crystal reports. I would like to access the second SQL server using the readOnly flag in the connection string: ApplicationIntent=ReadOnly

In my C# class I am running the crystal reports based on ConnectionInfo()

var myConnectionInfo = new ConnectionInfo();

Tables myTables = reportDocument.Database.Tables;

for (int i = 0; i < myTables.Count; i++)
{
    var myTable = myTables[i];
    var myTableLogonInfo = myTable.LogOnInfo;
    myConnectionInfo.ServerName = 'serverName';
    myConnectionInfo.DatabaseName = 'databaseName';
    myConnectionInfo.UserID = 'userId';
    myConnectionInfo.Password = 'password';
    myTableLogonInfo.ConnectionInfo = myConnectionInfo;
    myTable.ApplyLogOnInfo(myTableLogonInfo);
}

I haven't found a way to set ApplicationIntent=ReadOnly though. Is this supposed to be done setting myConnectionInfo.Attributes? Unfortunately I haven't found an answer on this yet but unanswered questions:

  • https://archive.sap.com/discussions/thread/3861287
  • https://archive.sap.com/discussions/thread/3791155
like image 413
jrn Avatar asked Oct 29 '22 04:10

jrn


2 Answers

Unfortunately I did not find a way to use the flag ApplicationIntent=ReadOnly in my posted code snippet.

What I ended up doing:
Instead of using the load balancer IP address (or host name), I am using the IP address of the reporting server directly. I couldn't find any written documentation whether or not one can use ApplicationIntent=ReadOnly.

like image 142
jrn Avatar answered Nov 15 '22 06:11

jrn


Rather than using ConnectionInfo, you could use System.Data.SqlClient.SqlConnectionStringBuilder, which has a settable ApplicationIntent property.

like image 29
Rupert Morrish Avatar answered Nov 15 '22 04:11

Rupert Morrish