StrataFrame Forum

Crystal Reports \SF Connection Info

http://forum.strataframe.net/Topic12873.aspx

By Michael Reese - 11/30/2007

Can anyone help me with establishing a connection to SF at runtime. I keep getting an error using the Crystal "ConnectionInfo" with the SF "ConnectionString"

Thanks Much.

Sample code

******************************************************

Private Sub ConfigureCrystalReports()

Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()

myConnectionInfo.DatabaseName = "MYDB"

myConnectionInfo.UserID = "Test"

myConnectionInfo.Password = "1234"

myConnectionInfo.ServerName = "MYServer"

northwindCustomersReport = New ReportDocument()

Dim reportPath As String = Application.StartupPath & "\" & "SubjectReport.rpt"

northwindCustomersReport.Load(reportPath)

myCrystalReportViewer.ReportSource = northwindCustomersReport

SetDBLogonForReport(myConnectionInfo, northwindCustomersReport)

End Sub

Private Sub SetDBLogonForReport(ByVal myConnectionInfo As ConnectionInfo, ByVal myReportDocument As ReportDocument)

Dim myTables As Tables = myReportdocument.Database.Tables

For Each myTable As CrystalDecisions.CrystalReports.Engine.Table In myTables

Dim myTableLogonInfo As TableLogOnInfo = myTable.LogOnInfo

myTableLogonInfo.ConnectionInfo = myConnectionInfo

myTable.ApplyLogOnInfo(myTableLogonInfo)

Next

End Sub

By StrataFrame Team - 12/3/2007

What's the error you're getting?  It might be that you have to build the connection info like you are doing in your example, and to parse out the pieces of the connection string, you can use SqlConnectionStringBuilder.

Dim builder As New SqlConnectionStringBuilder(DataBasics.DataSources(String.Empty).ConnectionString)

The builder then has all the properties like DataSource, InitialCatalog, Username, Password, WindowsAuth, etc.

By Michael Reese - 12/3/2007

Hey Ben,

I am getting a connection error,

Failed to open the connection.
Failed to open the connection.
C:\DOCUME~1\MICHAEL\LOCALS~1\Temp\rptSingleSubject

By Trent L. Taylor - 12/4/2007

It sounds like your connection is not correct.  Were you sure to include the data base (Initial Catalog)?  If you ToString the SqlConnectionStringBuilder what does your connection string look like?  More than likely you are getting a valid error.