打开和关闭sql连接 [英] open and closing the sql connection

查看:154
本文介绍了打开和关闭sql连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我正确的方法,如何在asp.net中打开和关闭sql连接

please tell me correct way, how to open and close the sql connection in asp.net

推荐答案

private static void OpenConnection(string connectionString)
{
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        connection.Open();
        Console.WriteLine("ServerVersion: {0}", connection.ServerVersion);
        Console.WriteLine("State: {0}", connection.State);
    }
}





如果你想按条件检查那么...... :)





if you want to check by condition then...:)

String strConn = System.Configuration.ConfigurationManager.ConnectionStrings["conStr"].ToString();
OracleConnection con = new OracleConnection(strConn);
if(if(con.State == ConnectionState.Open)
{
lable1.text= "Connection is Open";
}
else
{
lable1.text= "Connection is close";
}


这篇关于打开和关闭sql连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆