asp.net2.0中用于数据库连接的配置

在web.config中插入如下代码:

<configuration>

  <connectionStrings>

      <add name="Oracle" connectionString="Data Source=dbname;User ID=user;Password=password;" provideName="System.Data.OracleClient" />

      <add name="Sql" connectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=dbname" provideName="System.Data.SqlClient />

  </connectionStrings>

</configuration>

 

 

定义连接的方法

Oracle 方法

using System.Data.OracleClient { private OracleConnection con; private void Open() { if ( con == null || con.State.ToString() == "Closed") { con = new OracleConnection(ConfigurationManager.ConnectionStrings["Oracle"].ConnectionsString); con.Open(); } } private void RunCmd(string cmdName) { Open(); OracleCommand cmd = new OracleCommand(cmdName,con); cmd.ExecuteNonQuery(); } }

Sql 方法

using System.Data.SqlClient { private SqlConnection con; private void Open() { if ( con== null || con.State.ToString() == "Closed") { con = new SqlConection(ConfigurationManager.ConnectionStrings["Sql"].ConnectionString); con.Open(); } private void Close() { if (con!= null) con.Close(); } private void Dispose() { if (con!= null) { con.Close(); con = null; } } }

 

 

待完善后,上传SQL及ORACLE通用类库

你可能感兴趣的:(oracle,sql,数据库,Security,null,asp.net)