在MSDN中,.net的数据库连接字符串都有详细的说明,我这里以代码范例的方式罗列一些,具体的每一项代表的意义可以参看MSDN. ADO.net 中数据库连接方式(微软提供) 微软提供了以下四种数据库连接方式: System.Data.SqlClient.SqlConnection SqlConnection conn SqlConnection conn SqlConnection conn = new SqlConnection( SqlConnection conn = new SqlConnection( SqlConnection myConn = new SqlConnection conn = new SqlConnection( 更多字符串连接说明请看MSDN: System.Data.OleDb.OleDbConnection OleDbConnection conn = new OleDbConnection(@”Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\MyWeb\81\05\GrocerToGo.mdb”); OleDbConnection conn = new OleDbConnection( OleDbConnection conn = new OleDbConnection( OleDbConnection conn = new OleDbConnection( OleDbConnection conn = new OleDbConnection( OracleConnection myConn = new System.Data.OracleClient.OracleConnection( OdbcConnection conn = new OdbcConnection( OdbcConnection conn = new OdbcConnection( OdbcConnection conn = new OdbcConnection( OdbcConnection conn = new OdbcConnection(“DSN=dsnname”); DB2Connection myConn = new IBM.Data.DB2.DB2Connection( DB2Connection myConn = new IBM.Data.DB2.DB2Connection(“DATABASE = SAMPLE”); BdpConnection myConn = new Borland.Data.Provider.BdpConnection(“assembly=Borl 更多数据库连接信息,以及非ADO.net的连接字符串可以参看:
System.Data.OleDb.OleDbConnection
System.Data.SqlClient.SqlConnection
System.Data.Odbc.OdbcConnection
System.Data.OracleClient.OracleConnection
下面我们以范例的方式,来依次说明:
常用的一些连接字符串(C#代码):
= new SqlConnection( “Server=(local);Integrated Security=SSPI;database=Pubs”);
= new SqlConnection(“server=(local)\\NetSDK;database=pubs;Integrated Security=SSPI”);
“Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;”);
” data source=(local);initial catalog=xr;integrated security=SSPI;
persist security info=False;workstation id=XURUI;packet size=4096; “);
System.Data.SqlClient.SqlConnection(“Persist Security Info=False;Integrated
Security=SSPI;database=northwind;server=mySQLServer”);
” uid=sa;pwd=passwords;initial catalog=pubs;data source=127.0.0.1;Connect Timeout=900″);
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataSqlClientSqlConnectionClassConnectionStringTopic.asp
常用的一些连接字符串(C#代码):
@”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=Microsoft.Jet.OLEDB.4.0; Data Source=c:\bin\LocalAccess40.mdb”);
“Provider=SQLOLEDB;Data Source=MySQLServer;Integrated Security=SSPI”);
System.Data.OracleClient.OracleConnection
常用的一些连接字符串(C#代码):
“Data Source=Oracle8i;Integrated Security=yes”);
System.Data.Odbc.OdbcConnection
常用的一些连接字符串(C#代码):
OdbcConnection conn = new OdbcConnection(
“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”);
OdbcConnection conn = new OdbcConnection(
“Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=c:\bin”);
其他厂商提供的数据库连接:
“DATABASE = SAMPLE;UID=<username>; PWD=<password>;”);
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”);
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。
http://www.connectionstrings.com/
ado.net中数据库连接方式_ado.net应用
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ado.net中数据库连接方式_ado.net应用
相关推荐
-      从站长角度浅谈交换链的发展与创新
-      企业在建设网站时为什么要采用静态页面
-      增强IIS安全的简单措施
-      百度的对私服站点的收录和清除
-      网上偷拍栏目全部关闭对优化SEO是喜还是忧?
-      用301定向叫网站的PR飞起来
-      Google PR劫持
-      SEO角度看网站重新设计