国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

介紹幾種 ADO.net 中的數據庫連接方式

2024-07-21 02:38:56
字體:
來源:轉載
供稿:網友

  在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:/MyWeb/81/05/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。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 定安县| 柯坪县| 温宿县| 南华县| 集安市| 澜沧| 扶风县| 太康县| 镇坪县| 喀喇沁旗| 八宿县| 资中县| 滦南县| 岳阳县| 芦山县| 平度市| 莱阳市| 闽侯县| 修水县| 东丰县| 裕民县| 小金县| 印江| 封丘县| 屯门区| 永登县| 灵丘县| 金川县| 织金县| 宣威市| 于田县| 阿坝县| 麻江县| 略阳县| 叶城县| 合阳县| 古丈县| 固镇县| 石柱| 深州市| 通州区|