ADO.net 中資料庫連接方式(微軟提供)

來源:互聯網
上載者:User
ado|資料|資料庫|資料庫連接|微軟 在MSDN中,.net的資料庫連接字串都有詳細的說明,我這裡以代碼範例的方式羅列一些,具體的每一項代表的意義可以參看MSDN.

ADO.net 中資料庫連接方式(微軟提供)

微軟提供了以下四種資料庫連接方式:
System.Data.OleDb.OleDbConnection
System.Data.SqlClient.SqlConnection
System.Data.Odbc.OdbcConnection
System.Data.OracleClient.OracleConnection
下面我們以範例的方式,來依次說明:

System.Data.SqlClient.SqlConnection
常用的一些連接字串(C#代碼):

SqlConnection conn = new SqlConnection( "Server=(local);Integrated Security=SSPI;database=Pubs");

SqlConnection conn = new SqlConnection("server=(local)\NetSDK;database=pubs;Integrated Security=SSPI");

SqlConnection conn = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;");

SqlConnection conn = new SqlConnection(" data source=(local);initial catalog=xr;integrated security=SSPI;
persist security info=False;workstation id=XURUI;packet size=4096; ");

SqlConnection myConn = new System.Data.SqlClient.SqlConnection("Persist Security Info=False;Integrated
Security=SSPI;database=northwind;server=mySQLServer");

SqlConnection conn = new SqlConnection( " uid=sa;pwd=passwords;initial catalog=pubs;data source=127.0.0.1;Connect Timeout=900");

更多字串串連說明請看MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataSqlClientSqlConnectionClassConnectionStringTopic.asp

System.Data.OleDb.OleDbConnection
常用的一些連接字串(C#代碼):

OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\MyWeb5\GrocerToGo.mdb");

OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Password=;
User ID=Admin;Data Source=grocertogo.mdb;");

OleDbConnection conn = new OleDbConnection("Provider=MSDAORA; Data Source=ORACLE8i7;Persist Security Info=False;Integrated Security=yes");

OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\bin\LocalAccess40.mdb");

OleDbConnection conn = new OleDbConnection("Provider=SQLOLEDB;Data Source=MySQLServer;Integrated Security=SSPI");

更多字串串連說明請看MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataOleDbOleDbConnectionClassConnectionStringTopic.asp?frame=true
System.Data.OracleClient.OracleConnection
常用的一些連接字串(C#代碼):
OracleConnection myConn = new System.Data.OracleClient.OracleConnection(
"Data Source=Oracle8i;Integrated Security=yes");

更多字串串連說明請看MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataOracleClientOracleConnectionClassConnectionStringTopic.asp?frame=true
System.Data.Odbc.OdbcConnection
常用的一些連接字串(C#代碼):
OdbcConnection conn = new OdbcConnection(
"Driver={SQL Server};Server=MyServer;Trusted_Connection=yes;Database=Northwind;");

OdbcConnection conn = new OdbcConnection(
"Driver={Microsoft ODBC for Oracle};Server=ORACLE8i7;
Persist Security Info=False;Trusted_Connection=yes");

OdbcConnection conn = new OdbcConnection(
"Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\bin\nwind.mdb");

OdbcConnection conn = new OdbcConnection(
"Driver={Microsoft Excel Driver (*.xls)};DBQ=c:\bin\book1.xls");


OdbcConnection conn = new OdbcConnection(
"Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=c:\bin");

OdbcConnection conn = new OdbcConnection("DSN=dsnname");

更多字串串連說明請看MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataOdbcOdbcConnectionClassConnectionStringTopic.asp?frame=true


其他廠商提供的資料庫連接:

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=Borl
and.Data.Mssql,Version=1.1.0.0,Culture=neutral,PublicKeyToken=91d62ebb5b0d1b1b;ve
ndorclient=sqloledb.dll;osauthentication=False;database=<database>;usernam
e=<user>;hostname=<host>;password=<password>;provider=MSSQL");

BdpConnection myConn = new Borland.Data.Provider.BdpConnection("assembly=Borl
and.Data.Db2,Version=1.1.0.0,Culture=neutral,PublicKeyToken=91d62ebb5b0d1b1b;ve
ndorclient=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




相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。