How To Use "DSN-Less" ODBC Connections with RDO and DAO (147875)
The information in this article applies to:
- Microsoft Visual Basic Professional Edition for Windows 5.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 5.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition, 32-bit, for Windows 4.0
- Microsoft Visual Basic Enterprise Edition, 32-bit, for Windows 4.0
- Microsoft Data Access Components 1.5
- Microsoft Data Access Components 2.0
- Microsoft Data Access Components 2.1
- Microsoft Data Access Components 2.5
This article was previously published under Q147875 SUMMARY
With Microsoft Visual Basic versions 4.0, 5.0, and 6.0 for Windows, you can
specify your ODBC (Open Database Connectivity) driver and server in your
connect string when using RDO (Remote Data Object) and DAO (Data Access
Objects) which eliminates the need to set up a DSN (Data Source Name). We
call this a "DSN- Less" ODBC connection because you do not need to set up a
DSN in order to access your ODBC database server.
To do this, you specify a "driver=" and "server=" parameter in your connect
string as in the following example. Note You must change Username= <username> and PWD =<strong password> to the correct values before you run this code. Make sure that Username has the appropriate permissions to perform this operation on the database.
cnstr = "driver={SQL Server};server=myserver;" & _
"database=mydb;Username=<username>;PWD=<strong password>;dsn=;"
Set cn = en.OpenConnection("", False, False, cnstr)
NOTE: The driver name must be surrounded by curly brackets. For example:
"{SQL Server}."
(CAUTION: DSN-Less connections will not work in Visual Basic 4.0 16-bit. If
you try to use them you will get a General Protection Fault in module
ODBC.DLL at 0006:080F.)
REFERENCES
Hitchhiker's Guide to Visual Basic and SQL Server, Microsoft Press.
ISBN: 1-55615-906-4.
Modification Type: | Minor | Last Reviewed: | 8/30/2004 |
---|
Keywords: | kbhowto kbRDO KB147875 |
---|
|