数据库连接字符串大全 之 SQL服务器篇
2008-06-08 11:45 TTlive 阅读(233) 评论(0) 编辑 收藏 举报
数据库的连接字符串经常使用,可是数据库的种类繁多,连接方式又分很多种,下面提供各个数据库各种方式的连接字符串方便使用的时候查询。
SQL服务器
ODBC连接方式
Oracle
标准安全连接 Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword; 信任连接 Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Trusted_Connection=Yes; 提示输入用户名和密码方式
OLE DB, OleDbConnection 连接方式(.NET)
这个有一点问题,首先你需要设置一个Prompt 属性等于adPromptAlways连接对象,然后在使用连接字符串
oConn.Properties("Prompt") = adPromptAlways Driver={SQL Server};Server=myServerAddress;Database=myDataBase; 标准安全连接 Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword; 信任连接 Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI; 指定服务器的连接 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地址连接
SqlConnection连接方式 (.NET)
这里的Data Source=190.190.200.100,1433 前面的190.190.200.100是IP地址,1433连接是端口
Provider=sqloledb;Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword; 标准安全连接 Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword; 标准安全另外一种连接写法 Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False; 信任连接 Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI; 信任连接另外一种连接写法 Server=myServerAddress;Database=myDataBase;Trusted_Connection=True; 指定服务器的连接 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; 指定包大小的连接
Data Shape连接方式
默认情况下, SQL服务器的微软.NET框架数据提供者设置网络包大小对8192个字节。然而这不一定是最好的,你可以根据你觉的合适的包大小设置包的大小,Packet Size= 就是设置包的大小值
Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False;Packet Size=4096; MS Data Shape Provider=MSDataShape;Data Provider=SQLOLEDB;Data Source=myServerAddress;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;
Oracle XE
标准连接
ODBC
Oracle XE (或 "Oracle Database 10g Express Edition")是自由分布的简化版本
Driver=(Oracle in XEClient);dbq=111.21.31.99:1521/XE;Uid=myUsername;Pwd=myPassword;新版本 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;
被信任连接(Oracle提供) Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;OSAuthent=1;
TNS-less连接 Provider=OraOLEDB.Oracle;Data Source=(DESCRIPTION=(CID=GTU_APP)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=myHost)(PORT=myPort)))(CONNECT_DATA=(SID=MyOracleSID)(SERVER=DEDICATED)));User Id=myUsername;Password=myPassword;
Oracle.DataAccess.Client.OracleConnection
被信任连接(微软提供) Provider=msdaora;Data Source=MyOracleDB;Persist Security Info=False;Integrated Security=Yes;
标准安全连接(Oracle提供) Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User Id=myUsername;Password=myPassword;
被信任连接(Oracle提供) Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;OSAuthent=1;
TNS-less连接 Provider=OraOLEDB.Oracle;Data Source=(DESCRIPTION=(CID=GTU_APP)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=myHost)(PORT=myPort)))(CONNECT_DATA=(SID=MyOracleSID)(SERVER=DEDICATED)));User Id=myUsername;Password=myPassword;
标准连接 Data Source=TORCL;User Id=myUsername;Password=myPassword; 综合的安全连接 Data Source=TORCL;Integrated Security=SSPI; 没有tnsnames.ora的ODP.NET连接 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
标准连接
指定用户名和密码的连接
省去tnsnames.ora的连接 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=/;
特许连接
运用密码失效功能的连接
代理验证连接 Data Source=myOracleDB;User Id=myUsername;Password=myPassword;Proxy User Id=pUserId;Proxy Password=pPassword;
Core Labs OraDirect (.NET) Data Shape这个方式只适合Oracle 8i release 3或者之后的版本
Data Source=MyOracleDB;Integrated Security=yes; 指定用户名和密码的连接
这个方式只适合Oracle 8i release 3或者之后的版本
Data Source=MyOracleDB;User Id=myUsername;Password=myPassword;Integrated Security=no;省去tnsnames.ora的连接 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); 代理验证连接 Data Source=myOracleDB;User Id=myUsername;Password=myPassword;Proxy User Id=pUserId;Proxy Password=pPassword;