Hello Guys
i'm trying to connect to a Crystal Report document with the follow code:
oReport = New ReportDocument()
oReport.Load(pathrldc)
oReport.DataSourceConnections.Item(0).SetConnection(sServerName, sBd, sDBUserID, sDBPwd)
But it just shows the exception that cann't connect to a database, if I try to use this code in VS 2008, it works ok, I also try to set the connection in every table but doesnt work
oReport = New ReportDocument()
oReport.Load(pathrldc)
oReport.DataSourceConnections.Item(0).SetConnection(sServerName, sBd, sDBUserID, sDBPwd)
oReport.DataSourceConnections.Item(0).SetLogon(sDBUserID, sDBPwd)
oReport.SetDatabaseLogon(sDBUserID, sDBPwd, sServerName, sBd)
Dim crTableLogOnInfo As TableLogOnInfo = New TableLogOnInfo()
Dim crConnectionInfo As ConnectionInfo = New ConnectionInfo()
Dim crDatabase As CrystalDecisions.CrystalReports.Engine.Database
Dim crTables As CrystalDecisions.CrystalReports.Engine.Tables
crConnectionInfo.ServerName = sServerName
crConnectionInfo.DatabaseName = sBd
crConnectionInfo.UserID = sDBUserID
crConnectionInfo.Password = sDBPwd
crConnectionInfo.Type = ConnectionInfoType.SQL
crConnectionInfo.IntegratedSecurity = False
crDatabase = oReport.Database
crTables = crDatabase.Tables
For Each crTable As CrystalDecisions.CrystalReports.Engine.Table In crTables
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next
'oReport.SetParameterValue("DocKey@", sDocumento)
oReport.Refresh()
exportOpts = oReport.ExportOptions
exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat
exportOpts.FormatOptions = pdfFormatOpts
exportOpts.ExportDestinationType = ExportDestinationType.DiskFile
diskOpts.DiskFileName = pathrldc & "Factura_" & sDocumento & "_" & Now.Date.ToString("ddMMyyyy") & "_" & Now.ToString("HHmm") & ".pdf"
exportOpts.DestinationOptions = diskOpts
oReport.Export()
Is needed to set up a new property to connect to DB
Regards
CM