Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How change connection form MSAccess to SQL Server programatically?

I have an rpt designed to accede to an MSAccess Database, everything works.

Now, I need change by programming the connection to against an access Database SQL Server that it possesses the same structure that access database .

The question is How I can that change?

Said differently, is there some way to change for code the connection of file Crystal Report of access to SQL Server?

VB.NET 2005

CR XI Relase 2 sp 4

My code, wrong:

Dim mireport As New CrystalDecisions.CrystalReports.Engine.ReportDocument

Dim logoninfo As New CrystalDecisions.Shared.TableLogOnInfo

Dim tlogoninfos As New CrystalDecisions.Shared.TableLogOnInfos

Dim connectionInfo As New CrystalDecisions.Shared.ConnectionInfo

Dim CrtableLogoninfos As New CrystalDecisions.Shared.TableLogOnInfos()

Dim CrtableLogoninfo As New CrystalDecisions.Shared.TableLogOnInfo()

Dim CrConnectionInfo As New CrystalDecisions.Shared.ConnectionInfo()

Dim CrTables As CrystalDecisions.CrystalReports.Engine.Tables

Dim CrTable As CrystalDecisions.CrystalReports.Engine.Table

mireport.Load("\report1.rpt")

With CrConnectionInfo

If Tipo_Base_Datos = "SQL" Then

.ServerName = "server"

.DatabaseName = "bdsql"

.UserID = ""

.Password = ""

.IntegratedSecurity = True

End If

If Tipo_Base_Datos = "ACCESS" Then

.ServerName = "c:\bd.mdb"

.DatabaseName = "c:\bd.mdb"

.UserID = ""

.Password = ""

End If

End With

CrTables = mireport.Database.Tables

For Each CrTable In CrTables

CrtableLogoninfo = CrTable.LogOnInfo

CrtableLogoninfo.ConnectionInfo = CrConnectionInfo

'MsgBox(crtableLogoninfo.ConnectionInfo.ServerName & " " & crtableLogoninfo.ConnectionInfo.DatabaseName)

CrTable.ApplyLogOnInfo(CrtableLogoninfo)

If Tipo_Base_Datos = "SQL" Then CrTable.Location = "bdsql".dbo." & CrTable.Location.Substring(CrTable.Location.LastIndexOf(".") + 1)

Next

Thanks.

Former Member
Not what you were looking for? View more on this topic or Ask a question