四种数据库连接方式

微软提供了以下四种数据库连接方式:常用的一些连接字符串(C#代码):
System.Data.SqlClient.SqlConnection       - SQL
System.Data.OleDb.OleDbConnection         - OLEDB
System.Data.Odbc.OdbcConnection           - ODBC
System.Data.OracleClient.OracleConnection - ORACLE

System.Data.SqlClient.SqlConnection //-----sql
Server=(local);DataBase=test;uid=sa;pwd=123
Server=localhost;Integrated Security=SSPI;DataBase=Pubs
Server=(local)\\NetSDK;database=pubs;Integrated Security=SSPI
Data Source=(local);Integrated Security=SSPI;Initial Catalog=pubs
Data Source=(local);initial catalog=pubs;integrated security=SSPI;persist security info=False;workstation id=XURUI;packet size=4096
Server=(local);Persist Security Info=False;Integrated Security=SSPI;DataBase=pubs
Data Source=127.0.0.1;uid=sa;pwd=sa;initial catalog=pubs;Connect Timeout=900

System.Data.OleDb.OleDbConnection //-----OLEDB
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\test.mdb;
Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath(ConfigurationSettings.AppSettings["数据库路径"]))
Provider=Microsoft.Jet.OLEDB.4.0;Password=;User ID=Admin;Data Source=grocertogo.mdb
Provider=MSDAORA; Data Source=ORACLE8i7;Persist Security Info=False;Integrated Security=yes
Provider=SQLOLEDB;Data Source=MySQLServer;Integrated Security=SSPI

System.Data.Odbc.OdbcConnection //------ODBC
Driver={SQL Server};Server=MyServer;Trusted_Connection=yes;Database=Northwind
Driver={Microsoft ODBC for Oracle};Server=ORACLE8i7;Persist Security Info=False;Trusted_Connection=yes
Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\bin\nwind.mdb
Driver={Microsoft Excel Driver (*.xls)};DBQ=c:\bin\book1.xls
Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=c:\bin
DSN=dsnname

System.Data.OracleClient.OracleConnection //------Oracle
OracleConnection myConn = new System.Data.OracleClient.OracleConnection("Data Source=Oracle8i;Integrated Security=yes");

其他厂商提供的数据库连接:
DB2Connection myConn = new IBM.Data.DB2.DB2Connection("DATABASE = SAMPLE;UID=<username>; PWD=<password>;");
DB2Connection myConn = new IBM.Data.DB2.DB2Connection("DATABASE = SAMPLE");

BdpConnection myConn = new Borland.Data.Provider.BdpConnection("assembly=Borland.Data.Mssql,Version=1.1.0.0,Culture=neutral,PublicKeyToken=91d62ebb5b0d1b1b;vendorclient=sqloledb.dll;osauthentication=False;database=<database>;username=<user>;hostname=<host>;password=<password>;provider=MSSQL");

BdpConnection myConn = new Borland.Data.Provider.BdpConnection("assembly=Borland.Data.Db2,Version=1.1.0.0,Culture=neutral,PublicKeyToken=91d62ebb5b0d1b1b;vendorclient=db2cli.dll;database=<database>;username=<user>;password=<password>;provider=DB2");

Connection Pooling

在SQL Server、OLE DB和.NET框架结构中的Data Provider中,都提供了隐式的连接池连接支持。你可以在ConnectionString中指定不同的参数值控制连接池的行为。比如下面的例子使OLE DB的连接池无效并自动地进行事务处理:
Provider=SQLOLEDB;OLE DB Services=-4;Data Source=localhost;Integrated Security=SSPI;
在SQL Server.NET Data Provider中提供了以下参数设置控制连接池的行为:Connection Lifttime、Connection Reset、Enlist、Max Pool Size、Min Pool Size和Pooling。

你可能感兴趣的:(数据库连接)