asp.net连接Oracle的方法
2012-03-13 19:39


方式1:直接利用.NET的oracle驱动连接
引用System.data.oracleclient;
1 using System.data.oracleclient;
2 string oradb = "Data Source=water;User Id=modis;Password=modis;Integrated Security=no";
3 OracleConnection conn = new OracleConnection(oradb);
4 conn.Open();
(我的环境为VS2005,oracle数据源连接只支持到10g以下。)
方式2:安装完ODP.net(Oracle Data Provider.NET),通过OLEDB连接。
引用System.Data.OleDb;
1 using System.Data.OleDb;
2 string oradb = "Provider=OraOLEDB.Oracle;Data Source=water;User Id=modis;Password=modis;";
3 OleDbConnection myConnection = new OleDbConnection(oradb);
4 myConnection.Open();
方式3:安装完ODP.net,通过Oracle的连接器
引用动态链接库Oracle.DataAccess.Client.
1 using Oracle.DataAccess.Client;
2 string oradb = "Data Source=water;User Id=modis;Password=modis;";
3 OracleConnection conn = new OracleConnection(oradb); // C#
4 conn.Open();

上面的连接字符串只适用于在本地配置了环境的情况,如果想连接远程服务器中的数据库,而你在本地有没有配置环境,你需要参考下面的连接字符串

//OracleConnextion方式

1,string strConnection = @"Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orcl)));User Id=system;Password=system";

//OleDbConnection方式

2,string strConnection = "Provider=MSDAORA.1;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST =127.0.0.1)(PORT=1521)))(CONNECT_DATA =(SERVICE_NAME =orcl)));Persist Security Info=False;User ID=system;Password=system;Unicode=True;pooling = true Connect providerName=System.Data.OracleClient";