关于数据库连接的问题
在database.cs里面有这样子的定义public class DataBase
{
private string _ConnStr = null;
#region 基本数据库操作篇
//**********************************>> 基本数据库操作篇 <<**********************************//
/// <summary>
/// 设置用于打开数据库的字符串
/// </summary>
/// <param name="str">MDB/OLE/SQL/ORA/连接字符串 (MDBpath/OleDbString/SqlConnString/OraConnString)</param>
/// <returns></returns>
///
public DataBase(string str)
{
if (str == "MDB")
_ConnStr = "Provider=Microsoft.Jet.Oledb.4.0;data source=" +
HttpContext.Current.Request.PhysicalApplicationPath + "/" + ConfigurationSettings.AppSettings["MDBpath"];
else if (str == "OLE")
_ConnStr = ConfigurationSettings.AppSettings["OleDbString"];
else if (str == "SQL")
_ConnStr = ConfigurationSettings.AppSettings["SqlConnString"];
else if (str == "ORA")
_ConnStr = ConfigurationSettings.AppSettings["OraConnString"];
else
_ConnStr = str;
}
}
在web.cs里面有这样子的调用
database db=database(sql)
以及这样子_dst = db.GetDs(strSql);
问题来了,我现在用2005来写,有一个类SqlHelper.cs,这里面我只有一个SQL的连接,如 public static readonly string ConnectionStringLocalTransaction = ConfigurationManager.ConnectionStrings["xwroom"].ConnectionString;
那么请问一下,我_dst = db.GetDs(strSql); 应该怎么写才能够调用SqlHelper.cs里面的连接
--------------------编程问答-------------------- web.config里配置对数据库连接就可以啦啊
SqlHelper.cs的数据库连接是写在web.config的connectionStrings节点里的,如:
<connectionStrings>
<add name="uni_dbconnection" connectionString="Data Source=(local);Initial Catalog=***;User ID=sa;Password=sa" providerName="System.Data.SqlClient"/>
</connectionStrings>
而database.cs里的数据库连接字符串是放在web.config的appSettings节点里,如:
<appSettings>
<add key="SQL" value="Data Source=(local);Initial Catalog=***;User ID=sa;Password=sa"/>
</appSettings>
你只要设置对连接就可以调用啦
补充:.NET技术 , ASP.NET