Subscribe to Subscribers

Resources » Code Snippets » Crystal Reports

Setting Connection for Crystal Report Programatically in VB.Net


Posted Date:     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"

No responses found. Be the first to respond...

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.


    Next Resource: Checkbox in Crystal Report
    Previous Resource: Add Serial number in Crystal Report
    Return to Resources
    Post New Resource
    Category: Crystal Reports


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Setting Connection for Crystal Report Programatically  .  Crystal Report  .  Crystal Report Connection code-behind  .  Crystal Report Connection  .  

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2013 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.