Solved

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

Posted on 2003-12-12
12
1,205 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
  • 4
  • 3
  • 2
  • +3
12 Comments
 
LVL 100

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 250 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 22

Assisted Solution

by:_TAD_
_TAD_ earned 250 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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. …
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

776 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