Got a script to run crystal report over ASP.Net, export and send to email. Everything works with just tables but it does not seem to like SQL Expression Fields over functions.
If I use the current database without applying logon everything works but if I change datasource (same database different environment) at runtime then the issue below (but only with sql expression over function).
Crystal 2008 runtime
ERROR:System.Runtime.InteropServices.COMException (0x80042018): The table %1 does not exist in the document. at CrystalDecisions.ReportAppServer.Controllers.DatabaseControllerClass.VerifyTableConnectivity(Object Table) at CrystalDecisions.CrystalReports.Engine.Table.TestConnectivity() at ScriptCodeClass.ApplyLogon(ReportDocument cr, ConnectionInfo ci) at ScriptCodeClass.Logon(ReportDocument cr, String server, String db, String id, String pass) at ScriptCodeClass.FunCreatePDFView(String lsHeader, String lsReportType, String msDatabaseUserId, String msDatabasePassword)
2 Answers
Answers 1
try to build the query as string in code first then pass its results to crystal reports to have the report and send it by email.
steps: 1) build a query string. 2) execute that string and fill a datatable inside a dataset with the results 3) use that dataset / datatable to generate the report in crystal reports
Answers 2
You have several choices: Add Key(s) in web.config as follow :
<add key="ServerName" value=""/> Name Or IP Address <add key="DataBaseName" value=""/> Database Name <add key="DatabaseUser" value=""/>User Name <add key="DatabasePassword" value=""/>Password
and call these keys in your reportviewer on load or on your event as :
Dim SERVER_NAME As String = ConfigurationManager.AppSettings("ServerName").ToString() Dim DATABASE_NAME As String = ConfigurationManager.AppSettings("DataBaseName").ToString() Dim DatabaseUser As String = ConfigurationManager.AppSettings("DatabaseUser").ToString() Dim DatabasePassword As String = ConfigurationManager.AppSettings("DatabasePassword").ToString()
add your code and login to DB
CrystalReportViewer.SetDatabaseLogon(DatabaseUser, DatabasePassword, SERVER_NAME, DATABASE_NAME)
then add your datasource:
CrystalReportViewer.SetDataSource
Or you can pass it directly through your viewer as follow:
CrystalReportViewer.SetDatabaseLogon("sa", "123", "Your_Server", "YourDB")
0 comments:
Post a Comment