Solved

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

Posted on 2003-12-12
12
1,199 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now