I have created a report using crystal reports.
Currently, I am using User DSN as its datasource.
But the main problem is the report only opens from the Main PC as I set trustedconnection = TRUE
.
I can change DSN from a LAN pc as Trusted Connection to FALSE and set UserId and Pwd manually through ODBC.
By doing so, reports work perfectly in LAN but my another problem is I have to
change the Database on program runtime.
All Database structures(schema),Tables, procedures,Views all are same, just have different names.
Now when I change Default Database from DSN programmatically everything works fine.
But this works only in Main PC because I can change DSN when trusted Connection = TRUE.. and I cannot enter Password to DSN programatically(searched).
I tried the following code that change Database and the CrystalReportViewer1 opens the report successfully without any error.
Dim myDBConnectionInfo As New ConnectionInfo()
With myDBConnectionInfo
.ServerName = My.Settings.SysSvName
.DatabaseName = Pubdbname
.UserID = “sa”
.Password = “sa123”
End With
orptname.Load("JVR.rpt")
orptname.SetParameterValue("@CompYear", PubYear1)
orptname.SetParameterValue("@CompNo", mComp1)
orptname.SetParameterValue("@fdatee", Format(CDate(FromDate.Text), "MM/dd/yyyy"))
orptname.SetParameterValue("@tdatee", Format(CDate(ToDate.Text), "MM/dd/yyyy"))
orptname.SetParameterValue("cfdate", Format(CDate(FromDate.Text), "MM/dd/yyyy"))
orptname.SetParameterValue("ctdate", Format(CDate(ToDate.Text), "MM/dd/yyyy"))
orptname.SetParameterValue("CName", PubCName)
orptname.SummaryInfo.ReportTitle = "JVR REPORT" & "_" & Format(CDate(FromDate.Text), "ddMMyyyy") & "-" & Format(CDate(ToDate.Text), "ddMMyyyy")
CReports.CRViewer.ReportSource = orptname
CReports.Show() '----- CrystalreportViewer1
But no Data is been retrived.
After this, I changed the database name to Test1 from which I created(used database to design) the Report and it showed the data successfully.
And again tried to change db to Test2 Shows no result(but Crystal Report Opens without any error Connection error.)
Changing DSN default database shows records successfully.
Currently, successful running code I am using is below.
With orptname
.DataSourceConnections.Item(0).SetConnection("DSNNAME", Pubdbname, True)
.SetParameterValue("ctdate", Format(CDate(ToDate.Text), "MM/dd/yyyy"))
.SetParameterValue("CName", PubCName)
.SummaryInfo.ReportTitle = "TEST REPORT" & "_" & Format(CDate(FromDate.Text), "ddMMyyyy") & "-" & Format(CDate(ToDate.Text), "ddMMyyyy")
CReports.CRViewer.ReportSource = orptname
CReports.Show()
End With
So what shall I do now ?
In short, I want that my Crystal Report opens in LAN PC also and I can set database dynamically. (All database have exact same schema)