Resources » Code Snippets » Crystal Reports

Setting Connection for Crystal Report Programatically in VB.Net


Posted Date: 14-Jul-2009  Last Updated:   Category: Crystal Reports    
Author: Member Level: Gold    Points: 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
GrnReport.Load(Server.MapPath("myReportdoc1.rpt"))
Dim chkstate As Boolean
chkstate = setConnection("My_ConnectionString", myReport)
If chkstate = False Then
MsgBox("Empty Connection String", MsgBoxStyle.Critical)
Response.Flush()
Response.End()
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
myTable.ApplyLogOnInfo(myTableLogonInfo)
Next
Return (True)
End Function


Thanks & Regards,
CK.


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?


Feedbacks      

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

    Anna Nicola
    More...
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India