473,243 Members | 1,546 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,243 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 1691
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: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.