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:
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
.
Rather than using ConnectionInfo, you could use System.Data.SqlClient.SqlConnectionStringBuilder, which has a settable ApplicationIntent property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With