G
Grant Stanley
I'm developing an application in VS.Net 2003 using C#, which uses Crystal
Reports.
When creating each report, crystal asks where the database to use is, so I
specify our SQL server using the ADO option. The problem is that these
database settings seem to get compiled into the report, so when we take the
application to our client it won't work on their systems.
Before running each report I run some code which is ment to reset the
database information to the correct settings (used by our client) for each
table. The problem is that the report has an SQL Query Command embedded in
it (this query unions two select statements), which when in design view in
crystal it just looks like another database table. The code which runs seems
to update the database information, but cannot update the location setting
for the query and therefore when the report is run, it will keep trying to
look at the SQL Server we used for development.
The Crystal Help suggests something like:
TableLogOnInfo logOnInfo = new TableLogOnInfo();
// Loop through every table in the report.
for(int i=0;i<report.Database.Tables.Count;i++)
{
// Set the connection information for the current table.
logOnInfo.ConnectionInfo.ServerName = DataSource;
logOnInfo.ConnectionInfo.DatabaseName = DatabaseName;
logOnInfo.ConnectionInfo.UserID = Username;
logOnInfo.ConnectionInfo.Password = Password;
report.Database.Tables.ApplyLogOnInfo(logOnInfo);
}
This doesn't work unless you add:
report.Database.Tables.Location = DatabaseName.dbo.TableName
The problem with this is that when it gets to the table called "Command"
which is the SQL Query, Crystal throws an exception because it decides that
"Command" is not a valid table in the specified database.
If you get the code to ignore the "Command" query/table then the report will
continue trying to access our SQL Server for this one query and not the
other one specified.
I've made sure that the SQL Query doesn't have any occurances of
"dbo.tablename" and instead just has "tablename". Both methods fail.
Does anyone know how to update the connection details for a SQL Command in
Crystal?
Thanks,
Grant
Reports.
When creating each report, crystal asks where the database to use is, so I
specify our SQL server using the ADO option. The problem is that these
database settings seem to get compiled into the report, so when we take the
application to our client it won't work on their systems.
Before running each report I run some code which is ment to reset the
database information to the correct settings (used by our client) for each
table. The problem is that the report has an SQL Query Command embedded in
it (this query unions two select statements), which when in design view in
crystal it just looks like another database table. The code which runs seems
to update the database information, but cannot update the location setting
for the query and therefore when the report is run, it will keep trying to
look at the SQL Server we used for development.
The Crystal Help suggests something like:
TableLogOnInfo logOnInfo = new TableLogOnInfo();
// Loop through every table in the report.
for(int i=0;i<report.Database.Tables.Count;i++)
{
// Set the connection information for the current table.
logOnInfo.ConnectionInfo.ServerName = DataSource;
logOnInfo.ConnectionInfo.DatabaseName = DatabaseName;
logOnInfo.ConnectionInfo.UserID = Username;
logOnInfo.ConnectionInfo.Password = Password;
report.Database.Tables.ApplyLogOnInfo(logOnInfo);
}
This doesn't work unless you add:
report.Database.Tables.Location = DatabaseName.dbo.TableName
The problem with this is that when it gets to the table called "Command"
which is the SQL Query, Crystal throws an exception because it decides that
"Command" is not a valid table in the specified database.
If you get the code to ignore the "Command" query/table then the report will
continue trying to access our SQL Server for this one query and not the
other one specified.
I've made sure that the SQL Query doesn't have any occurances of
"dbo.tablename" and instead just has "tablename". Both methods fail.
Does anyone know how to update the connection details for a SQL Command in
Crystal?
Thanks,
Grant