Completely Free .NET word API

Resources » Code Snippets » Crystal Reports

Setting Connection for Crystal Report Programatically in VB.Net

Updated: Category: Crystal Reports
Author: Member Level: GoldPoints: 6

Abstract :

This code shows how to Set Connection for Crystal Report Programaticaly

Include the namespaces

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Here is the code :

'Create an Instance of the report
Dim myReport As ReportDocument = New ReportDocument
Dim chkstate As Boolean
chkstate = setConnection("My_ConnectionString", myReport)
If chkstate = False Then
MsgBox("Empty Connection String", MsgBoxStyle.Critical)
End If
Public Function setConnectionCrystal(ByVal ConnectionString As String, ByVal myRep As ReportDocument)
Dim settings As ConnectionStringSettings
Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
settings = ConfigurationManager.ConnectionStrings(ConnectionString)
If settings Is Nothing Then
Return (False)
End If
Dim TestArray() As String = Split(settings.ConnectionString, ";")
Dim TA() As String
TA = Split(TestArray(0), "=")
myConnectionInfo.ServerName = TA(1)
TA = Split(TestArray(1), "=")
myConnectionInfo.DatabaseName = TA(1)
TA = Split(TestArray(2), "=")
myConnectionInfo.UserID = TA(1)
TA = Split(TestArray(3), "=")
myConnectionInfo.Password = TA(1)
Dim myTables As Tables = myRep.Database.Tables
For Each myTable As CrystalDecisions.CrystalReports.Engine.Table In myTables
Dim myTableLogonInfo As TableLogOnInfo = myTable.LogOnInfo
myTableLogonInfo.ConnectionInfo = myConnectionInfo
Return (True)
End Function

Thanks & Regards,

Did you like this resource? Share it with your friends and show your love!

Responses to "Setting Connection for Crystal Report Programatically in VB.Net"
Guest Author: kell   02 Oct 2013
where did you get the connectionStringSettings type?


Post Comment:

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)

    Type the numbers and letters shown on the left.

    Submit Article     Return to Article Index
    Subscribe to Subscribers
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John

    Online Members

    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India