日期:2014-05-19  浏览次数:20434 次

.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;
}