Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB and CR how to connect from a system DSN 1

Status
Not open for further replies.

mmarino

Programmer
Mar 22, 2002
42
US
I'm writing an VB app that needs to display reports. The reports are already in .rpt files, so I just need to call them (I'm using the OCX method).
I have gotten it to work by hardcoding the database information, like this:
Code:
 With frmReportSelect.rptReport
        .Connect = "DSN=MyServerName;UID=user;PWD=password;DSQ=MyDatabaseName"
End With
but now I need to run the app in two different systems, so I'm trying to find a better way to connect to the db. Can I use a system DSN? How is it done? Any code samples would really help.
Thanks,

Monica
 
I must strongly suggest that you don't hardcode anything in your app. You will pay for it later.
Do you have configuration information for your application saved somewhere, INI file, Registry? You can put the other saved information about your DB connection there also.
If the DB is something like SQL Server then your connection info shouldn't change between workstations, except maybe login information, and if you use Integrated Security you don't have to worry about that. If you are connecting to a file DB, such as Access, I suggest locating it on a central location and using UNC to reference it, e.g. \\Server\Public\Access.mdb.
However, you can pass a DSN name to the Crystal reports logon method like this:

C.LogOnServer "pdsodbc.dll", sCentralDSN, sCentralDBName, "", "" 'Log on to the ODBC connection/server.

That is code I use in my app to connect to the DB. In this case, Crystal expects a DSN name and has problems otherwise. The DSN is in my INI file too. Remember, no hardcoding.

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top