473,406 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Crystal Report Database Change

Hi, I've designed several Crystal Reports using the built in wizard.
They point to my database as HQ which is called "Thom". There is a
database called Sales on Thom which all the reports point to and get
their results from.

I'm ready to compile my program to give to the users at a different
site. They have a database server there called "Sidney" which had a
copy of the same "Sales" database on there. Is there a way I can
change the database of my report when I load it each time, it looks
like I'd have to go through each individual report and change the
database settings which would be very time consuming as I will be using
quite a few database servers with this program. I'd like to just
specify a database or dataset in the code.

This is how I call the report:

Dim Cr As New crRefunds

CrystalReportViewer1.ReportSource = Cr

it would be ideal if I could put a line in above, something like
cr.database = "Sidney". Is anything like this possible? If not what
is the best way to switch the database?

Any help or pointers will be greatly appreciated as I'm really stuck
with this one.

Nov 21 '05 #1
2 1697
Maybe this code can help you, I use it to run my reports on different db's
ofcourse the tablenames have to be the same.

hth Greetz Peter

add reference to CrystalDecisions.CrystalReports.Engine.dll

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports CrystalDecisions.ReportSource

Dim tblCurrent As Table
Dim crSubreportObject As SubreportObject
Dim subRepDoc As New ReportDocument
Dim crDatabase As CrystalDecisions.CrystalReports.Engine.Database
Dim crTables As Tables
Dim crTable As Table
Dim crSection As Section
Dim crSections As Sections
Dim crReportObjects As ReportObjects
Dim crReportObject As ReportObject
Dim crLogOnInfo As TableLogOnInfo
Dim crpConnectionInfo As New CrystalDecisions.Shared.ConnectionInfo
Dim crpTableLogOnInfo As New CrystalDecisions.Shared.TableLogOnInfo
Dim crReportDocument As New ReportDocument
crReportDocument.Load(psReportName)
CrystalReportViewer1.ReportSource = crReportDocument
CrystalReportViewer1.Zoom(2)
'
' Aanpassen server voor hoofdrapport
'
With crpConnectionInfo
.ServerName = "Yourserver"
.DatabaseName = "YourDataBase"
End With

'set this if you don't work with integrated security
'crpConnectionInfo.UserID = "user"
'crpConnectionInfo.Password = "password"
For Each tblCurrent In crReportDocument.Database.Tables
crpTableLogOnInfo = tblCurrent.LogOnInfo
crpTableLogOnInfo.ConnectionInfo = crpConnectionInfo
tblCurrent.ApplyLogOnInfo(crpTableLogOnInfo)
Next

'Set the sections collection with report sections
crSections = crReportDocument.ReportDefinition.Sections
For Each crSection In crSections
crReportObjects = crSection.ReportObjects
For Each crReportObject In crReportObjects
If crReportObject.Kind = ReportObjectKind.SubreportObject
Then

'If you find a subreport, typecast the reportobject to a
subreport object
crSubreportObject = CType(crReportObject,
SubreportObject)

'Open the subreport
subRepDoc =
crSubreportObject.OpenSubreport(crSubreportObject. SubreportName)

crDatabase = subRepDoc.Database
crTables = crDatabase.Tables

'Loop through each table and set the connection info
'Pass the connection info to the logoninfo object then
apply the
'logoninfo to the subreport

For Each crTable In crTables
With crpConnectionInfo
.ServerName = "YourServer"
.DatabaseName = "YourDataBase"
End With
crLogOnInfo = crTable.LogOnInfo
crLogOnInfo.ConnectionInfo = crpConnectionInfo
crTable.ApplyLogOnInfo(crLogOnInfo)
Next
End If
Next
Next
"Jasper Jones" <ja*******@gmail.com> schreef in bericht
news:11**********************@z14g2000cwz.googlegr oups.com...
Hi, I've designed several Crystal Reports using the built in wizard.
They point to my database as HQ which is called "Thom". There is a
database called Sales on Thom which all the reports point to and get
their results from.

I'm ready to compile my program to give to the users at a different
site. They have a database server there called "Sidney" which had a
copy of the same "Sales" database on there. Is there a way I can
change the database of my report when I load it each time, it looks
like I'd have to go through each individual report and change the
database settings which would be very time consuming as I will be using
quite a few database servers with this program. I'd like to just
specify a database or dataset in the code.

This is how I call the report:

Dim Cr As New crRefunds

CrystalReportViewer1.ReportSource = Cr

it would be ideal if I could put a line in above, something like
cr.database = "Sidney". Is anything like this possible? If not what
is the best way to switch the database?

Any help or pointers will be greatly appreciated as I'm really stuck
with this one.

Nov 21 '05 #2
This looks good, Peter. I will try this out now. Many thanks.

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Grant Stanley | last post by:
I'm developing an application in VS.Net 2003 using C#, which uses Crystal Reports. When creating each report, crystal asks where the database to use is, so I specify our SQL server using the ADO...
7
by: Phin | last post by:
I need your HELP! I've seen all the posts on using Crystal Reports within vs.net (vb.net) and changing a SQL query at runtime. When I tried to pass in a dataset into the crystal report at...
3
by: Diggler | last post by:
I was working on a report that is populated with three different tables in a strongly-typed dataset. The tables are populated from custom objects rather than directly from SQL Server. I loop...
7
by: Bernie Yaeger | last post by:
I can't believe that there aren't lots of developers who: 1. create a crystal report that connects to sql server 2. calls the report using the crystalreportviewer control to view it and then,...
7
by: Henry | last post by:
I am writing a Windows forms VB.Net/MS SQL application via VS 2003 that utilizes Crystal Reports. I want to be able to dynamically set the report data source at run time. I'm trying to change...
0
by: Ray | last post by:
Dear all, Now I am using the report document in vb.net to call the crystal report and I will set the database information in the report document. The code is as follow: ......
0
by: Chris | last post by:
I have the following situation in a VB.Net App I am working on: 1.)A report created in VS.Net 2003 using the CR.Net component of VS 2003. 2.)The datasource for the report is a Stored Proc in a...
0
by: Crash | last post by:
Hello everyone, I need help creating an asp page to view a crystal report, which requires that that I change the database connection dynamically. I thought I had this problem licked in CR7 (the...
5
by: jmar | last post by:
I posted a week ago and received one response. I'm looking for the opinion of several experienced .NET people before I proceed so I'm posting again. Sorry for the repost... I am updating a...
7
by: Jlo | last post by:
Hi, I have a c# winforms application. When I call the report file, it shows me all the records in the table. How can I make it to call only a particular range. i have the following code...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.