SQL Server 2005
SQL Native Client ODBC Driver
標准安全連接
Driver={SQL Native Client};Server=myServerAddress; Database=myDataBase;Uid=myUsername;Pwd=myPassword;
受信的連接
Driver={SQL Native Client}; Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;
"Integrated Security=SSPI" 與 "Trusted_Connection=yes" 是相同的。
連接到一個SQL Server實例
指定服務器實例的表達式和其他SQL Server的連接字符串相同。
Driver={SQL Native Client};Server=myServerName/theInstanceName;Database=myDataBase; Trusted_Connection=yes;
指定用戶名和密碼
oConn.Properties("Prompt") = adPromptAlways Driver={SQL Native Client}; Server=myServerAddress;Database=myDataBase;
使用MARS (multiple active result sets)
Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase; Trusted_Connection=yes;MARS_Connection=yes;
"MultipleActiveResultSets=true"與MARS_Connection=yes"是相同的。
使用ADO.NET 2.0作為MARS的模塊。 MARS不支持ADO.NET 1.0和ADO.NET 1.1。
驗證網絡數據
Driver={SQL Native Client}; Server=myServerAddress;Database=myDataBase; Trusted_Connection=yes;Encrypt=yes;
使用附加本地數據庫文件的方式連接到本地SQL Server Express實例
Driver={SQL Native Client};Server=./SQLExpress; AttachDbFilename=c:/asd/qwe/mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;
為何要使用Database參數?如果同名的數據庫已經被附加,那麼SQL Server將不會重新附加。
使用附加本地數據文件夾中的數據庫文件的方式連接到本地SQL Server Express實例
Driver={SQL Native Client};Server=./SQLExpress; AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname; Trusted_Connection=Yes;
為何要使用Database參數?如果同名的數據庫已經被附加,那麼SQL Server將不會重新附加。
數據庫鏡像
Data Source=myServerAddress; Failover Partner=myMirrorServer;Initial Catalog=myDataBase;Integrated Security=True;
SQL Native Client OLE DB Provider
標准連接
Provider=SQLNCLI;Server=myServerAddress; Database=myDataBase;Uid=myUsername;Pwd=myPassword;
受信的連接
Provider=SQLNCLI;Server=myServerAddress; Database=myDataBase;Trusted_Connection=yes;
連接到SQL Server實例
指定服務器實例的表達式和其他SQL Server的連接字符串相同。
Provider=SQLNCLI;Server=myServerName/theInstanceName; Database=myDataBase;Trusted_Connection=yes;
使用帳號和密碼
oConn.Properties("Prompt") = adPromptAlways oConn.Open "Provider=SQLNCLI;Server=myServerAddress;DataBase=myDataBase;
使用MARS (multiple active result sets)
Provider=SQLNCLI;Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;MarsConn=yes;
"MultipleActiveResultSets=true"和"MARS_Connection=yes"是相同的。
使用ADO.NET 2.0作為MARS的模塊。 MARS不支持ADO.NET 1.0和ADO.NET 1.1。
驗證網絡數據
Provider=SQLNCLI;Server=myServerAddress; Database=myDataBase;Trusted_Connection=yes;Encrypt=yes;
使用附加本地數據庫文件的方式連接到本地SQL Server Express實例
Provider=SQLNCLI;Server=./SQLExpress;AttachDbFilename=c:/asd/qwe/mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;
使用附加本地數據文件夾中的數據庫文件的方式連接到本地SQL Server Express實例
Provider=SQLNCLI;Server=./SQLExpress; AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;
數據庫鏡像
Data Source=myServerAddress;Failover Partner=myMirrorServer; Initial Catalog=myDataBase;Integrated Security=True;
SqlConnection (.NET)
標准連接
Data Source=myServerAddress; Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
Standard Security alternative syntax
Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False;
受信任的連接
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
Trusted Connection alternative syntax
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
連接到一個SQL Server的實例
指定服務器實例的表達式和其他SQL Server的連接字符串相同。
Server=myServerName/theInstanceName;Database=myDataBase;Trusted_Connection=True;
來自WinCE設備的安全連接
Data Source=myServerAddress; Initial Catalog=myDataBase; Integrated Security=SSPI;User ID=myDomain/myUsername;Password=myPassword;
僅能用於CE設備。
帶有IP地址的連接
Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;
使用MARS (multiple active result sets)
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True; MultipleActiveResultSets=true;
使用ADO.NET 2.0作為MARS的模塊。 MARS不支持ADO.NET 1.0和ADO.NET 1.1。
使用附加本地數據庫文件的方式連接到本地SQL Server Express實例
Server=./SQLExpress;AttachDbFilename=c:/asd/qwe/mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;
使用附加本地數據文件夾中的數據庫文件的方式連接到本地SQL Server Express實例
Server=./SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;
使用在SQL Server Express實例上的用戶實例
Data Source=./SQLExpress;Integrated Security=true;AttachDbFilename=|DataDirectory|/mydb.mdf;User Instance=true;
數據庫鏡像
Data Source=myServerAddress;Failover Partner=myMirrorServer;Initial Catalog=myDataBase;Integrated Security=True;
Asynchronous processing
Server=myServerAddress; Database=myDataBase; Integrated Security=True; Asynchronous Processing=True;
MySQL
MyODBC
MyODBC 2.50 本地數據庫
Driver={mySQL};Server=localhost;Option=16834;Database=myDataBase;
MyODBC 2.50 遠程數據庫
Driver={mySQL}; Server=myServerAddress;Port=3306; Option=131072;Stmt=; Database=myDataBase; Uid=myUsername; Pwd=myPassword;
MyODBC 3.51 本地數據庫
Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=myDataBase; User=myUsername;Password=myPassword;Option=3;
MyODBC 3.51 遠程數據庫
Driver={MySQL ODBC 3.51 Driver};Server=data.domain.com;Port=3306; Database=myDataBase; User=myUsername; Password=myPassword;Option=3;
OLE DB, OleDbConnection (.NET)
標准
Provider=MySQLProv; Data Source=mydb; User Id=myUsername; Password=myPassword;
Connector/Net 1.0 (.NET)
標准
Server=myServerAddress; Database=myDataBase; Uid=myUsername;Pwd=myPassword;
默認端口號是3306
指定端口號
Server=myServerAddress; Port=1234;Database=myDataBase; Uid=myUsername; Pwd=myPassword;
命名管道
Server=myServerAddress; Port=-1;Database=myDataBase; Uid=myUsername;Pwd=myPassword;
如果端口是-1,意思是告訴驅動程序使用命名管道網絡協議來連接數據庫。
MySqlConnection (.NET)
eInfoDesigns.dbProvider
Data Source=myServerAddress; Database=myDataBase;User ID=myUsername; Password=myPassword; Command Logging=false;
SevenObjects MySqlClient (.NET)
標准
Host=myServerAddress; UserName=myUsername; Password=myPassword; Database=myDataBase;
Core Labs MySQLDirect (.NET)
標准
User ID=root;Password=myPassword;Host=localhost;Port=3306;Database=myDataBase; Direct=true;Protocol=TCP;Compress=false;Pooling=true;Min Pool Size=0;Max Pool Size=100;Connection Lifetime=0;
MySQLDriverCS (.NET)
標准
Location=myServerAddress; Data Source=myDataBase; UserID=myUsername; Password=myPassword; Port=3306;Extended Properties="""";
Oracle
ODBC
新版本
Driver={Microsoft ODBC for Oracle}; Server=myServerAddress; Uid=myUsername;Pwd=myPassword;
舊版本
Driver={Microsoft ODBC Driver for Oracle}; ConnectString=OracleServer.world; Uid=myUsername; Pwd=myPassword;
OLE DB, OleDbConnection (.NET)
標准連接
此連接字符串適用了微軟的驅動。
Provider=msdaora;Data Source=MyOracleDB; User Id=myUsername; Password=myPassword;
受信連接
Provider=msdaora; Data Source=MyOracleDB; Persist Security Info=False; Integrated Security=Yes;
標准連接
由Oracle提供的驅動。
Provider=OraOLEDB. Oracle;Data Source=MyOracleDB; User Id=myUsername; Password=myPassword;
受信連接
Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;OSAuthent=1;
Oracle.DataAccess.Client.OracleConnection
標准
Data Source=TORCL;User Id=myUsername; Password=myPassword;
標准安全連接
Data Source=TORCL;Integrated Security=SSPI;
使用ODP.NET而不使用tnsnames.ora
Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost) (PORT=MyPort)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID))); User Id=myUsername;Password=myPassword;
OracleConnection, Oracle Data Provider, ODP.NET.
System.Data.OracleClient.OracleConnection.
標准
用於8i RC3及以後的版本
Data Source=MyOracleDB;Integrated Security=yes;
指定用戶名和密碼
用於8i RC3及以後的版本
Data Source=MyOracleDB; User Id=myUsername; Password=myPassword; Integrated Security=no;
忽略tnsnames.ora
另一種不需要使用DSN的連接方式
SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost) (PORT=MyPort))(CONNECT_DATA=(SERVICE_NAME=MyOracleSID))); uid=myUsername;pwd=myPassword;
使用上面的連接字符串可能會導致Visual Studio報告錯誤。
如果您在使用中出現了這些問題,請使用下面的這種連接方式。
Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort)) (CONNECT_DATA=(SERVICE_NAME=MyOracleSID))); User Id=myUsername; Password=myPassword;
使用連接池
如果連接池服務程序找不到已經存在的連接池,它將根據連接字符串創建一個新的池。
否則將循環使用池中已存在的連接。
Data Source=myOracleDB; User Id=myUsername; Password=myPassword;Min Pool Size=10;Connection Lifetime=120; Connection Timeout=60;Incr Pool Size=5;Decr Pool Size=2;
Windows身份驗證
Data Source=myOracleDB;User Id=/;
特權連接
使用SYSDBA
Data Source=myOracleDB;User Id=SYS;Password=SYS; DBA Privilege=SYSDBA;
特權連接
使用SYSOPER
Data Source=myOracleDB;User Id=SYS;Password=SYS;DBA Privilege=SYSOPER;
密碼過期處理過程
當使用一個連接字符串連接數據庫後,出現"密碼已過期"的錯誤時。
請執行OpenWithNewPassword命令來提供新密碼。
Data Source=myOracleDB;User Id=myUsername;Password=myPassword; oConn.OpenWithNewPassword(sTheNewPassword);
Proxy驗證
Data Source=myOracleDB; User Id=myUsername; Password=myPassword;Proxy User Id=pUserId; Proxy Password=pPassword;
Core Labs OraDirect (.NET)
Standard
User ID=myUsername; Password=myPassword; Host=ora;Pooling=true; Min Pool Size=0;Max Pool Size=100;Connection Lifetime=0;
Data Shape
MS Data Shape
Provider=MSDataShape.1;Persist Security Info=False;Data Provider=MSDAORA; Data Source=orac;User Id=myUsername; Password=myPassword;
AS/400 (iSeries)
IBM .Net Data Provider
您需要使用 IBM.Data.DB2.iSeries 命名空間
DataSource=myServerAddress;UserID=myUsername; Password=myPassword;DataCompression=True;
OLE DB, OleDbConnection (.NET)
IBM Client Access OLE DB 適配器
Provider=IBMDA400;Data Source=MY_SYSTEM_NAME;User Id=myUsername; Password=myPassword;
MY_SYSTEM_NAME是在OperationsNavigator中的系統連接名稱。
IBM Client Access OLE DB 適配器
Provider=IBMDA400;Data Source=MY_SYSTEM_NAME;User Id=myUsername; Password=myPassword;Default Collection=MY_LIBRARY;
MY_SYSTEM_NAME是系統連接的名稱,MY_LIBRARY是iSeries Navigator中library的名稱。
ODBC
IBM Client Access ODBC 驅動
Driver={Client Access ODBC Driver (32-bit)};System=my_system_name; Uid=myUsername; Pwd=myPassword;
IBM iSeries Access ODBC 驅動
這個驅動需要比IBM Client Access ODBC的驅動更新。
Driver={iSeries Access ODBC Driver};System=my_system_name; Uid=myUsername; Pwd=myPassword;
Caché
ODBC
標准
DRIVER={InterSystems ODBC};SERVER=myServerAddress; DATABASE=myDataBase; UID=myUsername;PWD=myPassword;
特定端口
DRIVER={InterSystems ODBC};SERVER=myServerAddress;PORT=12345; DATABASE=myDataBase; UID=myUsername;PWD=myPassword;
特定協議
DRIVER={InterSystems ODBC};SERVER=myServerAddress;PORT=12345; DATABASE=myDataBase; PROTOCOL=TCP;STATIC CURSORS=1;UID=myUsername;PWD=myPassword;
IBM DB2
OLE DB, OleDbConnection (.NET)
TCP/IP
Provider=DB2OLEDB;Network Transport Library=TCPIP;Network Address=XXX.XXX.XXX.XXX; Initial Catalog=MyCtlg;Package Collection=MyPkgCol;Default Schema=Schema;User ID=myUsername; Password=myPassword;
APPC
Provider=DB2OLEDB;APPC Local LU Alias=MyAlias;APPC Remote LU Alias=MyRemote; Initial Catalog=MyCtlg;Package Collection=MyPkgCol; Default Schema=Schema;User ID=myUsername;Password=myPassword;
IBM提供的OLE DB適配器
TCP/IP
Provider=IBMDADB2;Database=myDataBase; Hostname=myServerAddress; Protocol=TCPIP;Port=50000; Uid=myUsername;Pwd=myPassword;
ODBC
標准
Driver={IBM DB2 ODBC DRIVER}; Database=myDataBase;Hostname=myServerAddress; Port=1234;Protocol=TCPIP;Uid=myUsername;Pwd=myPassword;
Firebird
ODBC - IBPhoenix Open Source
標准
Driver=Firebird/InterBase(r) driver;Uid=SYSDBA; Pwd=masterkey; DbName=D:/FIREBIRD/examples/TEST.FDB;
.NET - Firebird .Net Data Provider
標准
User=SYSDBA;Password=masterkey;Database=SampleDatabase.fdb; DataSource=localhost;Port=3050;Dialect=3; Charset=NONE;Role=; Connection lifetime=15;Pooling=true;MinPoolSize=0;MaxPoolSize=50;Packet Size=8192;ServerType=0;
Informix
ODBC
Informix 3.30
Dsn=;Driver={INFORMIX 3.30 32 BIT};Host=hostname;Server=myServerAddress; Service=service-name; Protocol=olsoctcp; Database=myDataBase;Uid=myUsername;Pwd=myPassword;
Informix-CLI 2.5:
Driver={Informix-CLI 2.5 (32 Bit)};Server=myServerAddress; Database=myDataBase; Uid=myUsername;Pwd=myPassword;
OLE DB
IBM Informix OLE DB Provider
Provider=Ifxoledbc.2;Password=myPassword; User ID=myUsername; Data Source=dbName@serverName;Persist Security Info=true;
IBM Informix .NET Provider
IBM.Data.Informix.IfxConnection(命名空間)
Database=myDataBase;Host=192.168.10.10; Server=db_engine_tcp; Service=1492; Protocol=onsoctcp;UID=myUsername;Password=myPassword;
Ingres
ODBC
DSN-less
Provider=MSDASQL.1;DRIVER=Ingres;SRVR=xxxxx;DB=xxxxx;Persist SecurityInfo=False;Uid=myUsername;Pwd=myPassword; SELECTLOOPS=N; ExtendedProperties="SERVER=xxxxx;DATABASE=xxxxx;SERVERTYPE=INGRES";
Interbase
ODBC, Easysoft
本地計算機
Driver={Easysoft IB6 ODBC}; Server=localhost ;Database=localhost:C:/mydatabase.gdb; Uid=myUsername; Pwd=myPassword;
遠程計算機
Driver={Easysoft IB6 ODBC}; Server=myServerAddress; Database=ComputerName: C:/mydatabase.gdb; Uid=myUsername;Pwd=myPassword;
ODBC, Intersolv
本地計算機
Driver={INTERSOLV InterBase ODBC Driver (*.gdb)}; Server=localhost; Database=localhost: C:/mydatabase.gdb; Uid=myUsername; Pwd=myPassword;
遠程計算機
Driver={INTERSOLV InterBase ODBC Driver (*.gdb)}; Server=myServerAddress; Database=ComputerName: C:/mydatabase.gdb;Uid=myUsername; Pwd=myPassword;
OLE DB, SIBPROvider
標准
provider=sibprovider;location=localhost:;data source=c:/databases/gdbs/mygdb.gdb; user id=SYSDBA; Password=masterkey;
版本 2.x
Provider=SIBPROvider.2; Data Source=localhost:c:/databases/gdbs/mygdb.gdb; Persist Security Info=False;
指定字符集
provider=sibprovider;location=localhost:;data source=c:/databases/gdbs/mygdb.gdb; user id=SYSDBA; Password=masterkey; character set=ISO8859_1;
指定角色
provider=sibprovider;location=localhost:; data source=c:/databases/gdbs/mygdb.gdb;user id=SYSDBA; Password=masterkey; role=DIGITADORES;
Lightbase
標准連接
標准
User=myUsername;Password=myPassword;UDB=USERBASE;Server=myServerAddress;
Paradox
ODBC
5.X
Driver={Microsoft Paradox Driver (*.db )}; DriverID=538;Fil=Paradox 5.X; DefaultDir=c:/pathToDb/;Dbq=c:/pathToDb/;CollatingSequence=ASCII;
7.X
Provider=MSDASQL.1;Persist Security Info=False; Mode=Read;Extended Properties=DSN=Paradox; DBQ=C:/myDb;DefaultDir=C:/myDb;DriverId=538; FIL=Paradox 7.X; MaxBufferSize=2048;PageTimeout=600;;Initial Catalog=C:/myDb;
請注意:以上的方法僅能從數據庫獲取數據。
Intersolv 3.11 ODBC Driver
7.X
DSN=MyDSN;AUT=1;CT=7;DQ=0;FOC=0;IS=1; PW=myPassword;USF=1;ULQ=1;
並不是所有參數都是必填的。大多數參數都能夠在DSN中進行設置。
Parameters definition
AUT - ApplicationUsingThreads
CT - CreateType
DB - Database
DSN - DataSourceName
DQ - DeferQueryEvaluation
FOC - FileOpenCache
IS - IntlSort
ND - NetDir
PW - Passwords
USF - UltraSafeCommit
ULQ - UseLongQualifiers
OleDbConnection (.NET)
標准
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:/myDb;Extended Properties=Paradox 5.x;
注意:您僅需要指定數據庫存放的地址而無需指定數據庫的名稱。
SQLBase
OLE DB
標准
Provider=SQLBaseOLEDB;Data source=myServerAddress; Location=myDataBase; User Id=myUsername; Password=myPassword;
SQLBase .NET Data Provider
標准SQLBase連接
DataSource=myServerAddress; UserId=myUsername; Password=myPassword;Poolsize=5;Connection Lifetime=60;
"Poolsize" 表示多少SQLBase連接被打開,不論它們是否被立即使用。默認值是5。
"Connection Lifetime" 表示連接存在多長時間(單位:秒)。默認是60秒。
SQL Serve
ODBC
標准連接
Driver={SQL Server};Server=myServerAddress; Database=myDataBase;Uid=myUsername;Pwd=myPassword;
受信的連接
Driver={SQL Server};Server=myServerAddress; Database=myDataBase;Trusted_Connection=Yes;
指定帳號和密碼
oConn.Properties("Prompt") = adPromptAlways Driver={SQL Server}; Server=myServerAddress;Database=myDataBase;
OLE DB, OleDbConnection (.NET)
標准連接
Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
受信的連接
Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
使用serverName/instanceName作為數據源可以指定SQL Server實例。
連接到一個SQL Server的實例
指定服務器實例的表達式和其他SQL Server的連接字符串相同。
Provider=sqloledb; Data Source=myServerName/theInstanceName; Initial Catalog=myDataBase;Integrated Security=SSPI;
指定帳戶和密碼
oConn.Provider = "sqloledb" oConn.Properties("Prompt") = adPromptAlways Data Source=myServerAddress;Initial Catalog=myDataBase;
使用IP地址的連接
Provider=sqloledb;Data Source=190.190.200.100,1433; Network Library=DBMSSOCN;Initial Catalog=myDataBase; User ID=myUsername; Password=myPassword;
SqlConnection (.NET)
標准連接
Data Source=myServerAddress;Initial Catalog=myDataBase; User Id=myUsername;Password=myPassword;
Standard Security alternative syntax
Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False;
受信任的連接
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
Trusted Connection alternative syntax
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
連接到SQL Server實例
指定服務器實例的表達式和其他SQL Server的連接字符串相同。
Server=myServerName/theInstanceName;Database=myDataBase; Trusted_Connection=True;
僅能用於CE設備。
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;User ID=myDomain/myUsername;Password=myPassword;
帶有IP地址的連接
Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase; User ID=myUsername;Password=myPassword;
指定包的大小
Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword; Trusted_Connection=False;Packet Size=4096;
默認的包大小為8192字節。
Data Shape
MS Data Shape
Provider=MSDataShape;Data Provider=SQLOLEDB;Data Source=myServerAddress; Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;