首页 > 其他 > 详细

测试连接

时间:2016-02-20 13:10:10      阅读:176      评论:0      收藏:0      [点我收藏+]

 

//Create the Connection object
string connectionString = WebConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
SqlConnection con = new SqlConnection(connectionString);
try
{
//Try to open the connection.
con.Open();
lblInfo.Text = "<b>Server Version:</b>" + con.ServerVersion;
lblInfo.Text += "<br/><b>Connection Is:</b>" + con.State.ToString();

}
catch(Exception err)
{
//handle an error by displaying the infromation.
lblInfo.Text = "Error reading the datebase." + err.Message;
}
finally
{
//Either way ,make sure the connection is properly closed
// even if the connection wasn‘t opened successfully
//calling close() won‘t cause an error.
con.Close();
lblInfo.Text = "<br/><b>Now Connection Is:</b>" + con.State.ToString();
}

测试连接

原文:http://www.cnblogs.com/CarryLi7938/p/5202960.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!