ADO connection database string Daquan (VP, Excel, Text, Sybase, .NET, etc.)

xiaoxiao2021-03-06  99

ADO connection database string (VP, Excel, text, sybase, .NET, etc.) (reproduced) 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).

Thase Sample Connection Strings Are Compiled by Carl Prothman, A Microsoft Visual Basic MVP Enjoy!

Table of ContentSodbc 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

.NET Managed Provider Connections SQL Client .NET Managed Provider (System.Data.sqlclient) OLE DB .NET Managed Provider (System.Data.OleDb) ODBC .NET Managed Provider (System.Data.odbc)

ODBC DSN ConnectionsUsing 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. ;-)

ODBC - DSN Oconn.open "DSN = Advworks;" & _ "UID = Admin;" & _ "PWD =;

You can also create and use a file dsn. The Use the Following ADO Connection String:

ODBC - File DSN Oconn.open "FileDSN = C: /SOMEPath/mydb.dsn;" & _ "uid =;" & _ "PWD =;"

For more information, See: About Odbc Data Sources and how to use file dsns and dsn-length connects

NOTE: The Problem with DSN Is That Users CAN (AND WILL) MODIFY THEM (OR DELETE BY MISTAKE) WITH A Trusted Connection IF Possible!

ODBC DSN-Less ConnectionsODBC Driver for AS / 400 Oconn.open "Driver = {Client Access ODBC Driver (32-bit)};" & _ "system = myas400;" & _ "uid = myusername;" & _ "PWD = mypassword; "

For more information, see: a fast path to as / 400 client / server

ODBC Driver for Access for Standard Security:

Oconn.open "Driver = {Microsoft Access Driver (* .mdb)};" & _ "dbq = c: /somepath/mydb.mdb;" & _ "UID = Admin;" & _ "PWD =;" if You Are useing a Workgroup (System Database):

Oconn.open "Driver = {Microsoft Access Driver (* .mdb)};" & _ "dbq = c: /somepath/mydb.mdb;" & _ "systemdb = c: /somepath/mydb.mdw;", _ "admin", ""

IF MDB IS LOCATED ON A NetWork Share:

Oconn.open "Driver = {Microsoft Access Driver (* .mdb)};" & _ "DBQ = // myserver / myshare / mypath / mydb.mdb;"

For more information, see: Microsoft Access Driver Programming Considances

Odbc driver for dbase opase opase opase opase .open "driver = {microsoft dbase driver (* .db)};" & _ "driverid = 277;" & _ "DBQ = C: / SomePath;"

Note: Specify THE FILENAME IN The SQL Statement. For example: ors.open "Select * from user.dbf", Oconn,, AdcmdText

Note: MDAC 2.1 (or greater) Requires The Borland Database Engine (BDE) To Update DBase DBF Files. (Q238431).

For More Information, See: DBase Driver Programming Considances

ODBC Driver for Excel Oconn.open "Driver = {Microsoft Excel Driver (* .xls)};" & _ "driverid = 790;" & _ "DBQ = C: /SOMEPath/Myspreadsheet.xls;" & _ "defaultdir = C: / somepath; "

For more information, see: Microsoft Excel Driver Programming Considances

ODBC Driver for mysql (via myodbc) to connect to a local database

Oconn.open "driver = {mysql};" & _ "server = myservername;" & _ "option = 16834;" & _ "Database = MyDB;" To Connect to A Remote Database

Oconn.open "driver = {mysql};" & _ "server = db1.database.com;" & _ "port = 3306;" & _ "option = 131072;" & _ "stmt =;" & _ "Database = MYDB; "& _" uid = myusername; "& _" pwd = mypassword; "

For more information, see: programs known to work with myodbc

ODBC Driver for Oracle for The Current Oracle ODBC Driver from Microsoft:

Oconn.open "driver = {microsoft odbc for oracle};" & _ "server = oracleserver.world;" & _ "uid = myusername;" & _ "pwd = mypassword;"

For The Older Oracle ODBC Driver from Microsoft:

Oconn.open "Driver = {Microsoft Odbc Driver for Oracle};" & _ "ConnectString = OraclesRver.World;" & _ "UID = myusername;" & _ "PWD = mypassword;"

For More Information, See: Connection String Format and Attributes

Odbc driver for paradox oconn.open "driver = {Microsoft paradox driver (* .db)};" & _ "driverid = 538;" & _ "Fil = paradox 5.x;" & _ "defaultdir = C: / dbpath /; "& _" DBQ = C: / dbpath /; "& _" collatingsequence = ascii; "

Note: MDAC 2.1 (or greater) Requires The Borland Database Engine (BDE) TO Update Paradox Isam FDBF Files. (Q230126).

For more information, see: Paradox Driver Programming ConsiderationSodbc Driver for SQL Server for Standard Security:

Oconn.open "Driver = {SQL Server};" & _ "Server = myservername;" & _ "Database = MyDatabaseName;" & _ "UID = myusername;" & _ "PWD = mypassword;"

For Trusted Connection Security:

Oconn.open "Driver = {SQL Server};" & _ "Server = myservername;" & _ "Database = MyDatabaseName;" & _ "UID =;" & _ "PWD =;"

'OR

Oconn.open "Driver = {SQL Server};" & _ "Server = myservername;" & _ "Database = MyDatabaseName;" & _ "Trusted_Connection = YES;"

To Prompt User for UserName and Password

Oconn.properties ("prompt") = adpromptalwaysoconn.open "Driver = {SQL Server};" & _ "Server = myserName;" & _ "Database = myDatabaseName;"

For more information, see: SqldriverConnect (ODBC)

ODBC Driver for Sybase if Using The Sybase System 11 ODBC Driver:

Oconn.open "driver = {sybase system 11};" & _ "SRVR = myservername;" & _ "uid = myusername;" & _ "pwd = mypassword;"

IF using the intersolv 3.10 Sybase ODBC DRIVER:

Oconn.open "Driver = {INTERSOLV 3.10 32-bit sybase};" & _ "srvr = myservername;" & _ "uid = myusername;" & _ "pwd = mypassword;"

For more information, see: Sybase System 10 ODBC Driver Reference GuideODBC Driver for Sybase SQL Anywhere oConn.Open "ODBC; Driver = Sybase SQL Anywhere 5.0;" & _ "DefaultDir = c: / dbpath /;" & _ "Dbf = c : /sqlany50/mydb.db; "& _" uid = myusername; "& _" pwd = mypassword; "DSN =" "" ";"

NOTE: INCLUDING TAG WITH A NULL STRING IS ABSOLUTELY CRITI ELSE You get the dreamed -7778 error.

For more information, see: Sybase SQL Anywhere User Guide

Odbc driver for teraData oconn.open "provider = teraData;" & _ "dbcname = mydbcname;" & _ "Database = MyDatabaseName;" & _ "uid = myusername;" & _ "PWD = mypassword;"

For More Information, See Teradata ODBC Driver

Odbc driver for text oconn.open "driver = {Microsoft text driver (* .txt; * .csv)};" & _ "dbq = c: / somepath /;" & _ "extensions = ASC, CSV, Tab, TXT "& _" Persist security info = false "

Note: Specify The FileName In The Sql Statement. For example:

Ors.open "Select * from customer.csv", _ Oconn, AdopenStatic, AdlockReadOnly, AdcmdText

For More Information, See: Text File Driver Programming Considances

ODBC Driver for Visual FoxPro With Database Container:

Oconn.open "Driver = {Microsoft Visual FoxPro Driver};" & _ "SourceType = DBC;" & _ "SourceDb = C: /SOMEPATH/MysourceDb.dbc;" & _ "Exclusive = NO;"

Without a database container (Free Table Directory): oConn.Open "Driver = {Microsoft Visual FoxPro Driver};" & _ "SourceType = DBF;" & _ "SourceDB = c: / somepath / mySourceDbFolder;" & _ "Exclusive = NO; "

For more information, see: Visual FoxPro Odbc Driver and Q165492

OLE DB DATA LINK ConnectionsData Link File (UDL) for Absolute Path:

Oconn.open "file name = c: /somepath/mydatabaseename.ud1;"

For Relative Path:

Oconn.open "file name = myDatabaseName.UDL;"

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 ConnectionSole DB Provider for AS / 400 Oconn.open "provider = IBMDA400;" & _ "Data Source = MyAS400;" "" "" "" "" "" "" "" ""

For more information, see: a fast path to as / 400 client / server

OLE DB Provider for Active Directory Service Oconn.open "provider = adsdsoobject;" & _ "user id = myusername;" & _ "password = mypassword;"

For more information, See: Microsoft Ole DB Provider for Microsoft Active Directory Service

OLE DB Provider for DB2 oConn.Open = "Provider = DB2OLEDB;" & "Network Transport Library = TCPIP;" & "Network Address = MyServer;" & _ "Package Collection = MyPackage;" & "Host CCSID = 1142" "Initial Catalog = mydb; "&" user ID = myusername; "& _" password = mypassword; "for more information, see: ole DB Provider for DB2 and INF: Configuring Data Sources for the Microsoft Ole DB Provider for DB2

OLE DB Provider for Index Server Oconn.open "provider = msidxs;" & _ "Data Source = MyCatalog;"

For More Information, See: Microsoft Ole DB Provider for Microsoft Indexing Service

OLE DB Provider for Internet Publishing Oconn.open "provider = msdaipp.dso;" & _ "data source = http: // mywebsite / mydir;" & _ "user id = myusername;" & _ "password = mypassword;"

For more information, see: Microsoft Ole DB Provider for Internet Publishing and Q245359

OLE DB Provider for Microsoft Jet for Standard Security:

Oconn.open "provider = microsoft.jet.Oledb.4.0;" & _ "data source = c: /somepath/mydb.mdb;" & _ "user ID = admin;" & _ "password =;"

IF using a workgroup (System Database):

Oconn.open "provider = microsoft.jet.oledb.4.0;" & _ "data source = c: /somepath/mydb.mdb;" & _ "Jet OLEDB: System Database = mysystem.mdw;", _ "admin" ""

Note, Remember to Convert Both the mdb and the mdw to the 4.0 database format When Using the 4.0 ole DB provider.if MDB HAS A DATABASE Password:

Oconn.open "provider = microsoft.jet.Oledb.4.0;" & _ "data source = c: /somepath/mydb.mdb;" & _ "Jet OLEDB: Database Password = mydbpassword;", _ "admin", " "

IF MDB IS LOCATED ON A NetWork Share:

Oconn.open "provider = microsoft.jet.oledb.4.0;" & _ "data source = // myserver / myshare / mypath / mydb.mdb;

IF Want To Open Up The Access Database Exclusive:

Oconn.mode = admodeshareExClusiveoconn.open "provider = microsoft.jet.Oledb.4.0;" & _ "data source = c: /somepath/mydb.mdb;" & _ "user id = admin;" & _ "password =; "

For more information, see: ole db provider for Microsoft Jet, Q191754, Q225048, Q239114, And Q271908

You Can Also Open An Excel Spreadsheet Using The "OLE DB Provider for Microsoft Jet"

Oconn.open "provider = microsoft.jet.oledb.4.0;" & _ "data source = c: /somepath/myexcelspreadsheet.xls;" & _ "extended Properties =" "" ""

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 theselection into the recordset. If "HDR = No", then the provider will includethe 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"

Oconn.open "provider = microsoft.jet.oledb.4.0;" & _ "data source = c: / somepath /;" & _ "extended Properties =" "" "" "" "" "" "" "" "" "" "" "" "" "" "" " 'TEN OPEN A Recordset Based on a select on the actual fileors.open "Select * from mytextfile.txt", Oconn, AdopenStatic, AdlockReadOnly, AdcmdText

For more information, see: Q262537

OLE DBASES for odbc Databases for Access (JET):

Oconn.open "provider = msdasql;" & _ "driver = {Microsoft Access Driver (* .mdb)};" & _ "dbq = c: /somePath/mydb.mdb;" & _ "uid = myusername;" & _ _ "Pwd = mypassword;"

For SQL Server:

Oconn.open "provider = msdasql;" & _ "driver = {SQL Server};" & _ "server = myservername;" & _ "Database = myDatabaseName;" & _ "uid = myusername;" & _ "pwd = mypassword "

For more information, See: Microsoft Ole DB Provider for ODBC

OLE DB Provider for Oracle (from Microsoft) Oconn.open "provider = msdara;" & _ "Data Source = Myoracledb;" & _ "User ID = myusername;" & _ "password = mypassword;"

For more information, See: Microsoft Ole DB Provider for Oracle

OLE DB Provider for Oracle (from Oracle) for Standard Security:

Oconn.open "provider = oraoledb.oracle;" & _ "data source = myoracledb;" & _ "user id = myusername;" & _ "password = mypassword;"

For A Trusted Connection:

Oconn.open "provider = oraoledb.racle;" & _ "data source = myoracledb;" & _ "user ID = /;" & _ "password =;" 'oroconn.open "provike = oraoledb.oracle;" & _ "Data Source = Myoracledb;" & _ "OSAUTHENT = 1;"

NOTE: "Data Source =" Must Be set to the appropriate Name Which is known to the name, for ibal naming, it is the alias in the tnsnames.ora file; for oracle names, it is the the Net8 service name.

For more information, See: Connecting to an an ORACLE DATABASE (NOTE, IF you get a logon Dialog, The 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 hasbeen written using the OLE DB Simple Provider Toolkit. Simple providers are intended to access datasources 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 arbitraryXML files. These XML files may contain the ADO XML persistence schema, but it is not required. Thishas been implemented by connecting the OSP to the MSXML2.DLL, therefore MSXML2. Dll or newer isrequired.

Oconn.open "provider = msdaosp;" & _ "data source = msxml2.dsoControl.2.6;"

Ors.open "http://webserver/virtualroot/myxmlfile.xml", Oconn

For more information, See: Microsoft OLE DB Simple Provider

OLE DB Provider for SQL Server for Standard Security:

Oconn.open "provider = sqloledb;" & _ "data source = myservername;" & _ "initial catalog = mydatabaseename;" & _ "user id = myusername;" & _ "password = mypassword;" for a trusted connection:

Oconn.open "provider = sqloledb;" & _ "data source = myservername;" & _ "initial catalog = mydatabaseename;" & _ "integrated security = sspi;"

To Connect to a "named instance" (SQL Server 2000)

Oconn.open "provider = sqloledb;" & _ "data source = myservername / inst2;" & _ "initial catalog = mydatabaseename;" & _ "user id = myusername;" & _ "password = mypassword;"

To Prompt User for UserName and Password:

Oconn.Provider = "sqloledb" Oconn.properties ("prompt") = adpromptalwaysoconn.open "data source = myservername;" & _ "Initial catalog = myDatabaseName;"

To Connect Via An IP Address:

Oconn.open "provider = sqloledb;" & _ "data source = xxx.xxx.xxx.xxx, 1433;" & _ "network library = dbmssocn;" & _ "initial catalog = myDatabaseName;" & _ "user id = Myusername; "& _" Password = mypassword; "

Note: - xxx.xxx.xxx.xxx is an ip address- "network library = dbmsoccn" tells ole db to use tcp / ip rather tour named pipes (Q238949) - 1433 Is The Default Port Number for SQL Server- you can Add "encrypt = yes" for Encryption

For more information, see: Microsoft OLE DB Provider for SQL ServerRemote Data Service (RDS) ConnectionsThe 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, 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):

With ordc .server = "http: // carl2" .sql = "select * from authors where state = 'ca'" .connect = "provider = SQLOLOLEDB;" & _ "data source = (local);" & _ " Initial catalog = pubs; "& _" user ID = sa; "& _" password =; ".refreshend with

WITH The RDS Default Handler Enabled (Recommend):

With ordc .server = "http: // carl2" .Handler = "msdfmap.handler" .connect = "data source = myconnecttag;" .sql = "mysqltag (" "" "" ")" .refreshend with

The Corresponding Connect and SQL Sections in The Default Handler /winnt/msdfmap.ini File Would Be:

[Connect MyConnectTAG] Access = readwriteconnect = "provider = SQLOLEDB; DATA SOURCE = (local); Initial Catalog = Pubs; user ID = sa; password =;"

[SQL mysqltag] SQL = "SELECT * from authors where state = '?'"

For More Information About The Rds Default Handler, See: Q243245, Q230680, And Rds Customization Handler Microsoft ArticlesRDS DataControl - URL Property to Get Records from A Remote Database:

With ordc .url = "http://carlp0/AUTHHORS_GETBYSTATE.ASP? State = CA" .refreshend with

To save, SET the URL Property to an ASP Web Page:

With ORDC .url = "http://carlp0/rdsdatacontrol/authors_save.asp" .submitchangesend with

For more information, see: RDS URL Property

ADO URL Connectionsado 2.5 Allows You To Open Up A Recordset Based On XML Returned from an ASP File Over Http. This Feature Doesn't Use RDS At ALL.

Ado Recordset To Get Records from A Remote Database:

ors.open "http://rlp0/AUTHORS_GETBYSTATATE.ASP? State = CA", _ AdopenStatic, AdlockBatchOptimistic

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 streamset ostm = new adod.com.streamors.save Ostm, AdpersistXML

'Use MSXML's XMLHTTP object to open ASP and post a XML streamSet oXMLHTTP = New MSXML2.XMLHTTP30oXMLHTTP.Open "POST", "http: //carlp0/Authors_Save.asp", FalseoXMLHTTP.Send oStm.ReadText

'If an error occurredif oxmlhttp.status = 500 Then Debug.print oxmlhttp.statustextenD IF

For More Information, See: Ado RecordSet's Open Method

. MS Remote Provider ConnectionsThe following connections strings use Microsoft's remote provider (MS Remote) The MS Remoteprovider 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:

Oconn.open "provim = MS Remote;" & _ "Remote Server = http: // myservername;" & _ "remote provider = msdasql;" & _ "DSN = Advworks;" & _ "uid = myusername;" & _ " "Pwd = mypassword;"

IF you want to use an ole db provider on the remote machine:

Oconn.open "provmote;" & _ "remote server = http: // myservername;" & _ "remote provider = microsoft.jet.Oledb.4.0;" & _ "data source = c: / somepath / mydb .mdb; ", _" admin "," "

If you want to use an ole db provider on the remote machine (VIA RDS DataFactory Default Handler):

Oconn.open "provmote;" & _ "remote server = http: // myservername;" & _ "Handler = msdfmap.handler;" & _ "Data Source = myadvworksconn;"

The corresponding entry in /winnt/msdfmap.ini file would be:

[Connect myadvworksconn] access = readwriteconnect = "provider = microsoft.jet.Oledb.4.0;" & _ "data source = mydb.mdb;" & _ "user id = admin;" & _ "password =;" MS Remote - SQL Server if you want to use an odbc dsn on the remote machine:

Oconn.open "provmote;" & _ "Remote Server = http: // myservername;" & _ "remote provider = msdasql;" & _ "DSN = MyDatabaseName;" & _ "uid = myusername;" & _ " "Pwd = mypassword;"

IF you want to use an ole db provider on the remote machine:

Oconn.open "provmote;" & _ "Remote Server = http: // myservername;" & _ "Remote Provider = SQLOLEDB;" & _ "Data Source = MyServerName;" & _ "Initial Catalog = myDatabaseName;" & _ "User ID = myusername;" & _ "Password = mypassword;"

If you want to use an ole db provider on the remote machine (VIA RDS DataFactory Default Handler):

Oconn.open "provmote;" & _ "Remote Server = http: // myservername;" & _ "handler = msdfmap.handler;" & _ "Data Source = mypubsconn;"

The corresponding entry in /winnt/msdfmap.ini file would be:

[Connect MyPubsConn] Access = ReadWriteConnect = "Provider = SQLOLEDB;" & _ "Data Source = myServerName;" & _ "Initial Catalog = myDatabaseName;" & _ "User ID = myUsername;" & _ "Password = myPassword;" For More Information, See: Microsoft Ole DB Remoting Provider and Q240838

Data Shape Provider ConnectionsMS DataShape - SQL Server oConn.Open "Provider = MSDataShape;" & _ "Data Provider = SQLOLEDB;" & _ "Data Source = mySQLServerName;" & _ "Initial Catalog = myDatabase;" & _ "User ID = Myusername; "& _" Password = mypassword; "

THEN USE A Shape Command with SQL STRINGS: SSQL = "Shape {Select * from authors}" & _ "append ({selection * from title} 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

.NET Managed Provider ConnectionsSQL Client .NET Managed Provider (System.Data.SqlClient) 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".

Dim OsqlConnection As Sqlclient.sqlConnectionDim Sconnstring As String

Sconnstring = "Data Source = (local);" & _ "Initial catalog = northwind;" & _ "integrated security = sspi;" & _ "pooling = true;" & _ "min pool size = 10;" & _ " max Pool Size = 50; "& _" Connection Lifetime = 30; "& _" Connection Reset = True; "& _" Enlist = True; "oSQLConnection = New SqlClient.SqlConnection (sConnString) oSQLConnection.Open () For more information ,: system.data.sql namespace and .NET DATA Providersnote: '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 (Eg Sqloledb, Msdaora, or Microsoft.jet.Oledb.4.0).

For SQL Server Ole DB Provider (for SQL Server 6.0 or Earlier)

Dimooledbconnection as oledb.oledbconnectionDim sconnstring as string

sConnString = "Provider = sqloledb;" & _ "Data Source = myServerName;" & _ "Initial Catalog = myDatabaseName;" & _ "User Id = myUsername;" & _ "Password = myPassword;" oOleDbConnection = New OleDb.OleDbConnection ( ooledbconnection.open ()

For Jet OLE DB Provider:

Dimooledbconnection as oledb.oledbconnectionDim sconnstring as string

Sconnstring = "provider = microsoft.jet.Oledb.4.0;" & _ "data source = c: /work/nwind.mdb;" & _ "user id = admin;" & _ "password ="; "ooledbconnection = New oledb.oledbconnection (sconnstring) oledbconnection.open () for more information, see: system.data.oledb namespace and .Net Data Providersnote: '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.odbcconnectionDim Sconnstring AS String

'Create and Open A New ODBC ConnectionsConnstring = "Driver = {SQL Server};" & _ "Server = mysqlServerName;" & _ "Database = MyDatabaseName;" & _ "UID = myusername;" & _ "pwd = mypassword;"

Oodbcconnection = new odbc.odbcconnection (sconnstring) odbcconnection.Open ()

For Oracle ODBC DRIVER:

DIM OODBCCONNECTION As Odbc.odbcconnectionDim Sconnstring AS String

'Create and Open A New ODBC ConnectionsConnstring = "Driver = {Microsoft Odbc for Oracle};" & _ "Server = Oracleserver.World;" & _ "UID = myusername;" & _ "PWD = mypassword;"

Oodbcconnection = new odbc.odbcconnection (sconnstring) odbcconnection.Open ()

For Access (JET) ODBC Driver:

DIM OODBCCONNECTION As Odbc.odbcconnectionDim Sconnstring AS String

'Create and Open A New ODBC ConnectionsConnstring = "Driver = {Microsoft Access Driver (* .mdb)};" & _ "DBQ = C: /SOMEPath/mydb.mdb;" & _ "UID = Admin;" & _ " PWD =; "ooDbcconnection = new odbc.odbcconnection (sconnstring) odbcconnection.Open ()

For All Other ODBC Drivers:

DIM OODBCCONNECTION As Odbc.odbcconnectionDim Sconnstring AS String

'Create and Open A New ODBC ConnectionsConnstring = "DSN = MyDSN;" & _ "UID = myusername;" & _ "PWD = mypassword;"

Oodbcconnection = new odbc.odbcconnection (sconnstring) odbcconnection.Open ()

For more information, see: Download Center

转载请注明原文地址:https://www.9cbs.com/read-123124.html

New Post(0)