?
Solved

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

Posted on 2003-12-12
12
Medium Priority
?
1,233 Views
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.

Thanks!
0
Comment
Question by:sky71276
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +3
12 Comments
 
LVL 101

Expert Comment

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

http://support.crystaldecisions.com/communityCS/FilesAndUpdates/SCR8_VB_RDC_DBPassword.exe.asp

mlmcc
0
 

Author Comment

by:sky71276
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 ***
0
 
LVL 12

Accepted Solution

by:
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
  Next
  ' 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
  CRViewer1.ViewReport
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

by:_TAD_
_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.





Summary:

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.


0
 
LVL 13

Expert Comment

by:EwaldL
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
http://support.crystaldecisions.com/communityCS/TechnicalPapers/cr_rdc9_connectionproperties.pdf.asp
0
 
LVL 13

Expert Comment

by:EwaldL
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
Next
0
 
LVL 12

Expert Comment

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

Expert Comment

by:EwaldL
ID: 9934546
Hi DRRYAN,
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.
0
 
LVL 12

Expert Comment

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

Expert Comment

by:EwaldL
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...
0
 

Expert Comment

by:yadav_surender
ID: 9940779
Hi

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

Cheers
Surender
0
 

Author Comment

by:sky71276
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.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month13 days, 4 hours left to enroll

777 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