By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,706 Members | 1,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,706 IT Pros & Developers. It's quick & easy.

Crystal report : how to create a connexion at run time

P: n/a
Hello everyone.

How to give the connexion information to a crystal report at run time ?
same question concerning the SQL string for data extraction ?

Is it "a must" to disconnect the report at the end of its conception
under VStudio ?

Thanks for any advice.

Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Serge Fournier" <sa********@free.fr> schrieb im Newsbeitrag
news:O8**************@TK2MSFTNGP15.phx.gbl...
Hello everyone.

How to give the connexion information to a crystal report at run time ?
same question concerning the SQL string for data extraction ?

Is it "a must" to disconnect the report at the end of its conception
under VStudio ?

Thanks for any advice.


HI Serge,

use this for reports and/or subreports:

Private Sub ReportInit(ByVal blRefreshLocation As Boolean)

Dim crSections As Sections
Dim crSection As Section
Dim crReportObjects As ReportObjects
Dim crReportObject As ReportObject
Dim crSubreportObject As SubreportObject

Dim crReportDocument As ReportDocument
Dim crSubreportDocument As ReportDocument

Dim crDatabase As Database
Dim crTables As Tables
Dim crTable As Table
Dim crTableLogOnInfo As TableLogOnInfo
Dim crConnectioninfo As ConnectionInfo

Dim myArrayList As ArrayList = New ArrayList

'declare an instance of the report and the connectionInfo object

crReportDocument = New ReportDocument
crConnectioninfo = New ConnectionInfo

crReportDocument.Load(mstrReportName)

'pass the necessary parameters to the connectionInfo object
With crConnectioninfo
.ServerName = mstrDBServerName
.DatabaseName = mstrDataBaseName
End With

'set up the database and tables objects to refer to the current
report
crDatabase = crReportDocument.Database
crTables = crDatabase.Tables

'loop through all the tables and pass in the connection info
For Each crTable In crTables
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectioninfo
If blRefreshLocation Then
crTable.Location = mstrDataBaseName & ".dbo." &
crTable.Location.Substring(crTable.Location.LastIn dexOf(".") + 1)
End If
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next

'set the crSections object to the current report's sections
crSections = crReportDocument.ReportDefinition.Sections

'loop through all the sections to find all the report objects
For Each crSection In crSections
crReportObjects = crSection.ReportObjects
'loop through all the report objects to find all the subreports
For Each crReportObject In crReportObjects
If crReportObject.Kind = ReportObjectKind.SubreportObject
Then
'you will need to typecast the reportobject to a
subreport
'object once you find it
crSubreportObject = CType(crReportObject,
SubreportObject)

'open the subreport object
crSubreportDocument =
crSubreportObject.OpenSubreport(crSubreportObject. SubreportName)

'set the database and tables objects to work with the
subreport
crDatabase = crSubreportDocument.Database
crTables = crDatabase.Tables

'loop through all the tables in the subreport and
'set up the connection info and apply it to the tables
For Each crTable In crTables
With crConnectioninfo
.ServerName = mstrDBServerName
End With
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectioninfo
If blRefreshLocation Then
crTable.Location = mstrDataBaseName & ".dbo." &
crTable.Location.Substring(crTable.Location.LastIn dexOf(".") + 1)
End If
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next
End If
Next
Next

crystalReportViewer.ReportSource = crReportDocument

End Sub
Nov 21 '05 #2

P: n/a
thanks
it's working as wanted.

"thomas wenning" <no*******************@gmx.de> a écrit dans le message de
news:ec**************@TK2MSFTNGP15.phx.gbl...

"Serge Fournier" <sa********@free.fr> schrieb im Newsbeitrag
news:O8**************@TK2MSFTNGP15.phx.gbl...
Hello everyone.

How to give the connexion information to a crystal report at run time ?
same question concerning the SQL string for data extraction ?

Is it "a must" to disconnect the report at the end of its conception
under VStudio ?

Thanks for any advice.

HI Serge,

use this for reports and/or subreports:

Private Sub ReportInit(ByVal blRefreshLocation As Boolean)

Dim crSections As Sections
Dim crSection As Section
Dim crReportObjects As ReportObjects
Dim crReportObject As ReportObject
Dim crSubreportObject As SubreportObject

Dim crReportDocument As ReportDocument
Dim crSubreportDocument As ReportDocument

Dim crDatabase As Database
Dim crTables As Tables
Dim crTable As Table
Dim crTableLogOnInfo As TableLogOnInfo
Dim crConnectioninfo As ConnectionInfo

Dim myArrayList As ArrayList = New ArrayList

'declare an instance of the report and the connectionInfo object

crReportDocument = New ReportDocument
crConnectioninfo = New ConnectionInfo

crReportDocument.Load(mstrReportName)

'pass the necessary parameters to the connectionInfo object
With crConnectioninfo
.ServerName = mstrDBServerName
.DatabaseName = mstrDataBaseName
End With

'set up the database and tables objects to refer to the current
report
crDatabase = crReportDocument.Database
crTables = crDatabase.Tables

'loop through all the tables and pass in the connection info
For Each crTable In crTables
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectioninfo
If blRefreshLocation Then
crTable.Location = mstrDataBaseName & ".dbo." &
crTable.Location.Substring(crTable.Location.LastIn dexOf(".") + 1)
End If
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next

'set the crSections object to the current report's sections
crSections = crReportDocument.ReportDefinition.Sections

'loop through all the sections to find all the report objects
For Each crSection In crSections
crReportObjects = crSection.ReportObjects
'loop through all the report objects to find all the

subreports For Each crReportObject In crReportObjects
If crReportObject.Kind = ReportObjectKind.SubreportObject
Then
'you will need to typecast the reportobject to a
subreport
'object once you find it
crSubreportObject = CType(crReportObject,
SubreportObject)

'open the subreport object
crSubreportDocument =
crSubreportObject.OpenSubreport(crSubreportObject. SubreportName)

'set the database and tables objects to work with the
subreport
crDatabase = crSubreportDocument.Database
crTables = crDatabase.Tables

'loop through all the tables in the subreport and
'set up the connection info and apply it to the tables
For Each crTable In crTables
With crConnectioninfo
.ServerName = mstrDBServerName
End With
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectioninfo
If blRefreshLocation Then
crTable.Location = mstrDataBaseName & ".dbo." & crTable.Location.Substring(crTable.Location.LastIn dexOf(".") + 1)
End If
crTable.ApplyLogOnInfo(crTableLogOnInfo)
Next
End If
Next
Next

crystalReportViewer.ReportSource = crReportDocument

End Sub

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.