17,740
社区成员
发帖
与我相关
我的任务
分享
<appSettings>
<!--数据库连接串-->
<add key="connectionStrings" value="Data Source=192.168.0.21;Initial Catalog=DBName;User ID=sa;Password=sa;Connection Timeout=60;"/>
</appSettings>
public static SqlConnection GetSqlConnection()
{
try
{
string strSql = ConfigurationManager.AppSettings["connectionStrings"];
SqlConnection SqlCon = new SqlConnection(strSql);
if (SqlCon != null)
{
SqlCon.Open();
}
return SqlCon;
}
catch(Exception me)
{
throw new Exception("Invalid ConnectionString! " + me.Message);
}
}