This page contains sample ADO connection strings for ODBC DSN / DSN-Less, OLE DB Providers, Remote Data Services (RDS), MS Remote, MS DataShape.
Also included are ADO.NET connection strings for each .NET Managed Provider (SQLClient, OLEDB, and ODBC).
These sample connection strings are compiled by Carl Prothman, a Microsoft Visual Basic MVP Enjoy!
Table of Contents ODBC DSN Connections DSN File DSN
ODBC DSN-Less Connections ODBC Driver for AS/400 ODBC Driver for access ODBC Driver for Dbase ODBC Driver for Excel ODBC Driver for MySQL ODBC Driver for Oracle ODBC Driver for Paradox ODBC Driver for SQL Server ODBC Driver for Sybase ODBC Driver for Sybase SQL Anywhere ODBC Driver for Text ODBC Driver for Teradata ODBC Driver for Visual FoxPro
OLE DB Data Link Connections Data Link File (UDL)
OLE DB Data Provider Connections OLE DB Provider for AS/400 OLE DB Provider for Active Directory Service OLE DB Provider for DB2 OLD DB Provider for Internet Publishing OLE DB Provider for Index Server OLE DB Provider for Microsoft Jet OLE DB Provider for ODBC Databases OLE DB Provider for Oracle (From Microsoft) OLE DB Provider for Oracle (From Oracle) OLE DB Provider for Simple Provider OLE DB Provider for SQL Server
Remote Data Service (RDS) Connections RDS Data Control - Connect Property RDS Data Control - URL Property
ADO URL Connections ADO Recordset
MS Remote Provider Connections MS Remote - access (Jet) MS Remote - SQL Server
Data Shape Provider Connections MS DataShape - SQL Server
ODBC DSN Connections Using an ODBC DSN (Data Source Name) is a two step process.
1) You must first create the DSN via the "ODBC Data Source Administrator" program found in your computer's Control Panel (or Administrative Tools menu in Windows 2000). Make sure to create a SYSTEM DSN (not a USER DSN) when using ASP. Note: You can also create the DSN via VB code.
2) Then use the following connection string - with your own DSN name of course. ;-)
For more inFORMation, see: About ODBC data sources and How to Use File DSNs and DSN-less Connections
Note: The problem with DSN is that Users can (and will) modify them (or delete by mistake), then your program won't work so well… So it's better to use a DSN-Less or OLE DB Provider connection string with a Trusted Connection if possible!
For more inFORMation, see: HOWTO: Use Data Link Files with ADO
Note: Windows 2000 no longer contains the "New | Microsoft Data Link" menu anymore. You can add the Data Link menu back in the menu list by running the "C:\Program Files\Common Files\System\Ole DB\newudl.reg" reg file, then right-click on the desktop and select "New | Microsoft Data Link" menu. Or you can also create a Data Link file by creating a text file and change it's file extension to ".udl", then double-click the file.
OLE DB Provider Connections OLE DB Provider for AS/400
Where "HDR=Yes" means that there is a header row in the cell range (or named range), so the provider will not include the first row of the selection into the recordset. If "HDR=No", then the provider will include the first row of the cell range (or named ranged) into the recordset.
For more inFORMation, see: Q278973
You can also open a Text File using the "OLE DB Provider for Microsoft Jet"
' Then open a recordset based on a select on the actual file oRs.Open "Select * From MyTextFile.txt", oConn, adOpenStatic, adLockReadOnly, adCmdText For more inFORMation, see: Q262537
Note: "Data Source=" must be set to the appropriate Net8 name which is known to the naming method in use. For example, for Local Naming, it is the alias in the tnsnames.ora file; for Oracle Names, it is the Net8 Service Name.
For more inFORMation, see: Connecting to an Oracle Database (Note, if you get a Logon dialog, then click Cancel, then perFORM a one-time free signup with Oracle's TechNet system)
OLE DB Provider for Simple Provider
The Microsoft OLE DB Simple Provider (OSP) allows ADO to access any data for which a provider has been written using the OLE DB Simple Provider Toolkit. Simple providers are intended to access data sources that require only fundamental OLE DB support, such as in-memory arrays or XML documents.
OSP in MDAC 2.6 has been enhanced to support opening hierarchical ADO Recordsets over arbitrary XML files. These XML files may contain the ADO XML persistence schema, but it is not required. This has been implemented by connecting the OSP to the MSXML2.DLL, therefore MSXML2.DLL or newer is required.
Note: - ***.***.***.*** is an IP address - "Network Library=DBMSSOCN" tells OLE DB to use TCP/IP rather than Named Pipes (Q238949) - 1433 is the default port number for SQL Server - You can also add "Encrypt=yes" for encryption
For more inFORMation, see: Microsoft OLE DB Provider for SQL Server
Remote Data Service (RDS) Connections The following examples show how to connect to a remote database using the RDS Data Control. When using the RDS DataControl's Server/SQL/Connect properties, the RDS DataControl uses the RDS DataFactory on the remote server. If you use the RDS DataControl's URL property, then the RDS DataFactory is not used at all.
WARNING: The RDS DataFactory can be a major security hole if not setup and configured correctly! For more inFORMation, see RDS FAQ #24
RDS DataControl - Connect Property
With the RDS default handler disabled (not recommend due to security risks):
With oRdc .Server = "http://carl2"; .Sql = "Select * From Authors Where State = 'CA'" .Connect = "Provider=sqloledb;" & _ "Data Source=(local);" & _ "Initial Catalog=pubs;" & _ "User Id=sa;" & _ "Password=;" .Refresh End With
With the RDS default handler enabled (recommend):
With oRdc .Server = "http://carl2"; .Handler = "MSDFMAP.Handler" .Connect = "Data Source=MyConnectTag;" .Sql = "MySQLTag(""CA"")" .Refresh End With
The corresponding CONNECT and SQL sections in the default handler \WINNT\MSDFMAP.INI file would be:
To save changes, you must use the MSXML's XMLHTTP object to POST back the updated XML. The Recordset's Update and UpdateBatch methods will not work in this case.
' Save Recordset into Stream Set oStm = New ADODB.Stream oRs.Save oStm, adPersistXML
' Use MSXML's XMLHTTP object to open ASP and post a XML stream Set oXMLHTTP = New MSXML2.XMLHTTP30 oXMLHTTP.Open "POST", "http://carlp0/Authors_Save.asp";, False oXMLHTTP.Send oStm.ReadText
' If an error occurred If oXMLHTTP.Status = 500 Then Debug.Print oXMLHTTP.statusText End If
For more inFORMation, see: ADO Recordset's Open Method
MS Remote Provider Connections The following connections strings use Microsoft's remote provider (MS Remote). The MS Remote provider tells ADO to communicate with the remote server (via the RDS DataFactory) and to use the remote provider that is installed on the remote server.
WARNING: The RDS DataFactory can be a major security hole if not setup and configured correctly! For more inFORMation, see RDS FAQ #24
MS Remote - access (Jet)
If you want to use an ODBC DSN on the remote machine:
Then use a Shape command with SQL strings: sSQL = "SHAPE {select * from authors} " & _ "APPEND ({select * from titleauthor} AS chapter " & _ "RELATE au_id TO au_id)"
Or use a Shape command that calls Stored Procedures: sSQL = "SHAPE {exec spAuthors_LoadAll} " & _ "APPEND ({exec spTitleAuthor_LoadAll} AS chapter " & _ "RELATE au_id TO au_id)"
For more inFORMation, see: Microsoft Data Shaping Service for OLE DB and Q288409
The SQL Client .NET Managed Provide allows you to connect to a Microsoft SQL Server 7.0 or 2000 database. For Microsoft SQL Server 6.0 or earlier, use the OLE DB .NET Data Provider with the "SQL Server OLE DB Provider" (SQLOLEDB).
Dim oSQLConnection As SqlClient.SqlConnection Dim sConnString As String
For more inFORMation, see: System.Data.SQL Namespace and .NET Data Providers Note: 'SQL' namespace got renamed to 'SQLClient'
OLE DB .NET Managed Provider (System.Data.OleDb)
The OLE DB .NET Data Provider uses native OLE DB through COM interop to enable data access. To use the OLE DB .NET Data Provider, you must also use an OLE DB provider (e.g. SQLOLEDB, MSDAORA, or Microsoft.JET.OLEDB.4.0).
For SQL Server OLE DB Provider (for SQL Server 6.0 or earlier)
Dim oOleDbConnection As OleDb.OleDbConnection Dim sConnString As String
For more inFORMation, see: System.Data.OleDb Namespace and .NET Data Providers Note: 'ADO' namespace got renamed to 'OleDb'
ODBC .NET Managed Provider (System.Data.ODBC)
The ODBC .NET Data Provider is an add-on component to the .NET Framework SDK Beta 2. It provides access to native ODBC drivers the same way the OLE DB .NET Data Provider provides access to native OLE DB providers.
For SQL Server ODBC Driver:
Dim oODBCConnection As Odbc.OdbcConnection Dim sConnString As String
' Create and open a new ODBC Connection sConnString = "Driver={SQL Server};" & _ "Server=MySQLServerName;" & _ "Database=MyDatabaseName;" & _ "Uid=MyUsername;" & _ "Pwd=MyPassword;"
oODBCConnection = New Odbc.OdbcConnection(sConnString) oODBCConnection.Open()
For Oracle ODBC Driver:
Dim oODBCConnection As Odbc.OdbcConnection Dim sConnString As String
' Create and open a new ODBC Connection sConnString = "Driver={Microsoft ODBC for Oracle};" & _ "Server=OracleServer.world;" & _ "Uid=myUsername;" & _ "Pwd=myPassword;"
oODBCConnection = New Odbc.OdbcConnection(sConnString) oODBCConnection.Open()
For access (JET) ODBC Driver:
Dim oODBCConnection As Odbc.OdbcConnection Dim sConnString As String
' Create and open a new ODBC Connection sConnString = "Driver={Microsoft access Driver (*.mdb)};" & _ "Dbq=c:\somepath\mydb.mdb;" & _ "Uid=Admin;" & _ "Pwd=;"
oODBCConnection = New Odbc.OdbcConnection(sConnString) oODBCConnection.Open()
For all other ODBC Drivers:
Dim oODBCConnection As Odbc.OdbcConnection Dim sConnString As String
' Create and open a new ODBC Connection sConnString = "Dsn=myDsn;" & _ "Uid=myUsername;" & _ "Pwd=myPassword;"
oODBCConnection = New Odbc.OdbcConnection(sConnString) oODBCConnection.Open()