在MSDN中net的數據庫連接字符串都有詳細的說明我這裡以代碼范例的方式羅列一些具體的每一項代表的意義可以參看MSDN
中數據庫連接方式(微軟提供)
微軟提供了以下四種數據庫連接方式
SystemDataOleDbOleDbConnection
SystemDataSqlClientSqlConnection
SystemDataOdbcOdbcConnection
SystemDataOracleClientOracleConnection
下面我們以范例的方式來依次說明
SystemDataSqlClientSqlConnection
常用的一些連接字符串(C#代碼)
SqlConnection conn
= new SqlConnection( Server=(local)Integrated Security=SSPIdatabase=Pubs)
SqlConnection conn
= new SqlConnection(server=(local)\\NetSDKdatabase=pubsIntegrated Security=SSPI)
SqlConnection conn = new SqlConnection(
Data Source=localhostIntegrated Security=SSPIInitial Catalog=Northwind)
SqlConnection conn = new SqlConnection(
data source=(local)initial catalog=xrintegrated security=SSPI
persist security info=Falseworkstation id=XURUIpacket size= )
SqlConnection myConn = new
SystemDataSqlClientSqlConnection(Persist Security Info=FalseIntegrated
Security=SSPIdatabase=northwindserver=mySQLServer)
SqlConnection conn = new SqlConnection(
uid=sapwd=passwordsinitial catalog=pubsdata source=Connect Timeout=)
更多字符串連接說明請看MSDN
?url=/library/enus/cpref/html/frlrfSystemDataSqlClientSqlConnectionClassConnectionStringTopicasp
SystemDataOleDbOleDbConnection
常用的一些連接字符串(C#代碼)
OleDbConnection conn = new OleDbConnection(@Provider=MicrosoftJetOLEDBData Source=D\MyWeb\\\GrocerToGomdb)
OleDbConnection conn = new OleDbConnection(
@Provider=MicrosoftJetOLEDBPassword=
User ID=AdminData Source=grocertogomdb)
OleDbConnection conn = new OleDbConnection(
Provider=MSDAORA Data Source=ORACLEiPersist Security Info=FalseIntegrated Security=yes)
OleDbConnection conn = new OleDbConnection(
Provider=MicrosoftJetOLEDB Data Source=c\bin\LocalAccessmdb)
OleDbConnection conn = new OleDbConnection(
Provider=SQLOLEDBData Source=MySQLServerIntegrated Security=SSPI)
更多字符串連接說明請看MSDN
?url=/library/enus/cpref/html/frlrfSystemDataOleDbOleDbConnectionClassConnectionStringTopicasp?frame=true
SystemDataOracleClientOracleConnection
常用的一些連接字符串(C#代碼)
OracleConnection myConn = new SystemDataOracleClientOracleConnection(
Data Source=OracleiIntegrated Security=yes)
更多字符串連接說明請看MSDN
?url=/library/enus/cpref/html/frlrfSystemDataOracleClientOracleConnectionClassConnectionStringTopicasp?frame=true
SystemDataOdbcOdbcConnection
常用的一些連接字符串(C#代碼)
OdbcConnection conn = new OdbcConnection(
Driver={SQL Server}Server=MyServerTrusted_Connection=yesDatabase=Northwind)
OdbcConnection conn = new OdbcConnection(
Driver={Microsoft ODBC for Oracle}Server=ORACLEi
Persist Security Info=FalseTrusted_Connection=yes)
OdbcConnection conn = new OdbcConnection(
Driver={Microsoft Access Driver (*mdb)}DBQ=c\bin\nwindmdb)
OdbcConnection conn = new OdbcConnection(
Driver={Microsoft Excel Driver (*xls)}DBQ=c\bin\bookxls)
OdbcConnection conn = new OdbcConnection(
Driver={Microsoft Text Driver (*txt *csv)}DBQ=c\bin)
OdbcConnection conn = new OdbcConnection(DSN=dsnname)
更多字符串連接說明請看MSDN
?url=/library/enus/cpref/html/frlrfSystemDataOdbcOdbcConnectionClassConnectionStringTopicasp?frame=true
其他廠商提供的數據庫連接
DBConnection myConn = new IBMDataDBDBConnection(
DATABASE = SAMPLEUID=<username> PWD=<password>)
DBConnection myConn = new IBMDataDBDBConnection(DATABASE = SAMPLE)
BdpConnection myConn = new BorlandDataProviderBdpConnection(assembly=Borl
andDataMssqlVersion=Culture=neutralPublicKeyToken=debbbdbbve
ndorclient=sqloledbdllosauthentication=Falsedatabase=<database>usernam
e=<user>hostname=<host>password=<password>provider=MSSQL)
BdpConnection myConn = new BorlandDataProviderBdpConnection(assembly=Borl
andDataDbVersion=Culture=neutralPublicKeyToken=debbbdbbve
ndorclient=dbclidlldatabase=<database>username=<user>
password=<password>provider=DB)
Connection Pooling
在SQL ServerOLE DB和NET框架結構中的Data Provider中都提供了隱式的連接池連接支持你可以在ConnectionString中指定不同的參數值控制連接池的行為比如下面的例子使OLE DB的連接池無效並自動地進行事務處理
Provider=SQLOLEDBOLE DB Services=Data Source=localhostIntegrated Security=SSPI
在SQL ServerNET Data Provider中提供了以下參數設置控制連接池的行為Connection LifttimeConnection ResetEnlistMax Pool SizeMin Pool Size和Pooling
From:http://tw.wingwit.com/Article/program/net/201311/11727.html