URGENT!!! How to switch DB with VB6 and CR8.5?

Posted on 2003-12-12
Medium Priority
Last Modified: 2007-12-19
We have 2 environments : Development and Live, and reports are being moved from one to another.
Problem is that the reports point to different db's on different servers.

I want to make the db switch from a VB6 application (or VB.NET) so that there is no manual action needed.

The DB is a SQL Server 2000 and the connection in the reports is defined as OLEDB for SQL Server.

Question by:sky71276
  • 4
  • 3
  • 2
  • +3
LVL 101

Expert Comment

ID: 9928263
This samples shows how using an Access database.  The steps are the same for MS SQL



Author Comment

ID: 9928593
I already saw that sample, but it didn't do the trick...

*** I will be out of the office until monday, so it isn't that urgent anymore, the points remain though ***
LVL 12

Accepted Solution

DRRYAN3 earned 1000 total points
ID: 9929087
This is the code I use in the same environment you are working in.  This is for a SQL server database using the native SQL drivers in Crystal.  The key for your needs are the variables dbLocSQL and dbDatabaseName.

  dim dbUserID as string
  dim dbUserPass as string
  dim dbLocSQL as string
  dim dbDatabaseName as string
  dim RptFileName as string
  dim crApp as CRAXDRT.Application
  Dim crRepp As CRAXDRT.Report
  Dim crDBTab As CRAXDRT.DatabaseTable
  ' Get user login ID and password
  dbUserID = "someuser"
  dbUserPass = "mypassword"

  ' Define the SQL server to use.  This is the name of the server itself
  dbLocSQL = "SQLSvrName"

  ' Define the database within the SQL server to use
  dbDatabaseName = "MyDatabase"

  ' What Report to Print?
  RptFileName = "MyReport.RPT"

  ' Open The Report File
  Set crRepp = crApp.OpenReport(App.Path & RPTFileName)

  ' Set location of database based on stated SQL Server Name
  crRepp.Database.LogOnServer "p2ssql.dll", dbLocSQL, dbDatabaseName, dbUserID, dbUserPass

  ' Set table location to appropriate company server
  For Each crDBTab In crRepp.Database.Tables
    crDBTab.SetLogOnInfo dbLocSQL, dbDatabaseName, dbUserID, dbUserPass
  ' Turn on the broken Crystal Reports progress box.  Doesn't work.  Maybe someday.
  crRepp.DisplayProgressDialog = True

  ' Force Portrait orientation
  crRepp.PaperOrientation = crPortrait

  ' Associate report with the viewer
  CRViewer1.ReportSource = crRepp

  ' Display the report
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

LVL 22

Assisted Solution

_TAD_ earned 1000 total points
ID: 9930143

I don't tknow that my suggestion will help you with your current problem, but it may be usefull if you decide to make some design changes.

General Concept (This is the same concept I argued {and won} here at my place of employment):
   The functional users (at large) cannot be expected to have knowledge of how relational databases work.   It may also be prudent to hide a lot of data from functional users as most data in databases are not pertinant to functional data.  Therefore, I propose that a series of public views be created that the functional users are allowed to use for creating reports.  These views are the only entities that reports can be written from (no tables).
    All reports should be run using an ODBC connection.  ODBC connections can be created dynamically in code and used only for the life of the database connection to retrieve data.  This does two things: 1) locks down data/reports only to specified users with proper access.  2) Limits access to report access *ONLY* through your application _unless_ someone from IT has been given the proper authority to install the ODBC connection.  Which again means no unauthorized access.

The huge benifit to using ODBC when it comes to reports is that the report references the ODBC as if it were the Database name, and as you know ODBC is a dynamic connection to some database somewhere.

Now... the ODBC thing can be done directly against database tables (not necessarrily views).  The reason I explicitly state views is because of not only the above mentioned reason (lack of database knowledge), but also because either the program or the database can specify which views a user has access to.  Utiliziing role level security is a huge benifit to a corporation.


Use ODBC connections for reports. It may be a little slower than adirect OLEDB connection, but... hey this is a report.  It shouldn't have intense database processing with tons of cummunication back and forth.  You should make one request and receive a data payload.  That's it.

LVL 13

Expert Comment

ID: 9933875
my personal preference is on ole db, it tends to be heaps faster, and i leave the db security to sql server. if you want to restrict access to tables or rows, then create different users with different rights and provide everyone with the appropriate user name / password.

if you are using the rdc in cr 9, then use connectionproperties and the table location to change database

Dim crxDatabaseTable As CRAXDRT.DatabaseTable
For Each crxDatabaseTable In Report.Database.Tables
  With crxDatabaseTable.ConnectionProperties
    .Item("Provider") = "Provider Name"
    .Item("Data source") = "Server Name"
    .Item("Initial Catalog") = "Database Name"
    .Item("User ID") = "UID"
    .Item("Password") = "PWD"
  End With
  crxDatabaseTable.Location "database.dbo." + crxDatabaseTable.Name
Next crxDatabaseTable

also check this
LVL 13

Expert Comment

ID: 9933884
sorry, i hadn't seen you are in 8.5. here this should do the trick
Dim myReport As CRAXDRT.Report
Dim myTable As CRAXDRT.DatabaseTable
For Each myTable In myReport.Database.Tables
  myTable.SetLogOnInfo "ServerName", "DatabaseName", "User", "Password"
  myTable.Location = "Database.dbo." + myTable.Name
LVL 12

Expert Comment

ID: 9934402
EwaldL - I think I already posted similar code above.
LVL 13

Expert Comment

ID: 9934546
your code was missing the tableobject's location method. according to my experience this method is essential when pointing to a different SQL Server database at runtime. it needs to be executed in case the fully qualified table name changes.
LVL 12

Expert Comment

ID: 9935103
I'll buy that.  I don't ever use it.  I guess my databases are more stable than yours.  No offense meant.
LVL 13

Expert Comment

ID: 9935798
nothing to do with stability, just with the fact that the fully qualified table name in sql server contains the database name.

no offence taken, no offence meant...

Expert Comment

ID: 9940779

Instead of Developing DBSwitch you can set the path at runtime in crystal report because it would be better to write a generalize code.

You can write the following code
First decleare a recordset of the table which you r using in crystal report.

then write the following code

Report.Database.setdatasource rs,3,1
If you are using multiple tables then use
Report.Database.setdatasource rs2,3,2  ' and so on


Author Comment

ID: 10016265
Although I never got to what I exactly wanted, the accepted answer provided me with very useful code. When I read _TAD_ 's answer, I realized that a design change is more what we really want instead of a quick patch.

Thanks for the effort.

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question