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;





==================================================================



转载声明:本文转自

http://www.cnblogs.com/nuke/archive/2009/06/19/1506614.html




在此谨对原创作者和转载分享网友,致以深深的谢意,也愿更多的网友能够分享和学习经典资料,谢谢!