Click here to Skip to main content
15,921,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing C# application using crystal report. Am using the ODBC connection for the generation of the report. The point is that the system will have connect to different servers at run time and thus generate different report. But the problem is that, for the ODBC connection, i will have to edit the server name for the ODBC connection as and when the user selects to change the server. But I can not edit the server name at the
HTML
HKEY_LOCAL_MACHINE\\SOFTWARE\\ODBC\\ODBC.INI\\[databaseName]\\SERVER. 

The error message being that of security exception.
Please I need help immediately. If someone can really help me out i will be very glad. Thanks.
Posted
Updated 12-Sep-12 23:50pm
v2

1 solution

C#
reportDoc.Load(report);

ConnectionInfo connInfo = new ConnectionInfo();
connInfo.ServerName = "Driver={SQL Native Client};Server=SQLServer;";
connInfo.DatabaseName = "myDatabase";
connInfo.UserID = "myUser";
connInfo.Password = "myPassword";

TableLogOnInfo tableLogOnInfo = new TableLogOnInfo();
tableLogOnInfo.ConnectionInfo = connInfo;

foreach (Table table in reportDoc.Database.Tables)
{
    table.ApplyLogOnInfo(tableLogOnInfo);
    table.LogOnInfo.ConnectionInfo.ServerName = connInfo.ServerName;
    table.LogOnInfo.ConnectionInfo.DatabaseName = connInfo.DatabaseName;
    table.LogOnInfo.ConnectionInfo.UserID = connInfo.UserID;
    table.LogOnInfo.ConnectionInfo.Password = connInfo.Password;

    // Apply the schema name to the table's location
    table.Location = "mySchema." + table.Location;
}


Above Code is adopted from below article:

http://stackoverflow.com/questions/674363/how-do-i-change-a-crystal-reports-odbc-database-connection-at-runtime[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900