当前位置: 代码迷 >> ASP.NET >> .net2005 webconfig中调用数据库连接串有关问题
  详细解决方案

.net2005 webconfig中调用数据库连接串有关问题

热度:8644   发布时间:2013-02-26 00:00:00.0
.net2005 webconfig中调用数据库连接串问题?
.net2005   webconfig代码如下:
<configuration>
        <appSettings/>
        <connectionStrings>
                <add   name= "qkgj_webConnectionString "   connectionString= "Data   Source=.;Initial   Catalog=qkgj_web;User   ID=sa;Password=sa "
                        providerName= "System.Data.SqlClient "   />
        </connectionStrings>

在程序中如何调用数据库连接串?大家帮帮忙   谢谢了

------解决方案--------------------------------------------------------
protected SqlConnection GetConnetcion ()
{
string ConnectionString = ConfigurationManager.ConnectionStrings[ "qkgj_webConnectionString "].ToString();

SqlConnection Connection = null;
try
{
Connection = new SqlConnection(ConnectionString);
Connection.Open();
}
catch (Exception ex)
{
}
return Connection;
}
  相关解决方案