ASP.Net 中常用的数据库连接方式

  ASP.Net 中常用的数据库连接方式

     在ASP.Net中,连接数据库有以下四种方式:
 1.System.Data.OleDb.OleDbConnection
   2.System.Data.SqlClient.SqlConnection
 3.System.Data.Odbc.OdbcConnection
   4.System.Data.OracleClient.OracleConnection
      下面说下其具体用法:
 1.System.Data.SqlClient.SqlConnection
      常用的一些连接字符串:
 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");
2. 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");
 3.System.Data.OracleClient.OracleConnection
   常用的一些连接字符串(C#代码):
 OracleConnection myConn = new System.Data.OracleClient.OracleConnection("Data Source=Oracle8i;Integrated Security=yes");
4. 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");
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值