日期:2014-05-17 浏览次数:20575 次
string ConnectionString = ConfigurationManager.ConnectionStrings["ERPConnectionString"].ConnectionString;
public bool IsConnected()
{
SqlConnection connection = new SqlConnection(ConnectionString);//connectionString 数据库连接字符串
try
{
if (connection.State != ConnectionState.Open)
{
connection.Open();
}
return true;
}
catch
{
return false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (IsConnected() == true)
{
Context.Response.Write("ok");
}
}
//web.Config的代码
<connectionStrings>
<add name="ERPConnectionString" connectionString="Data Source=***.east.net;Initial Catalog=****_com_cn;Persist Security Info=True;User ID=****_com_cn;Password=****"/>
</connectionStrings>