public partial class Variables_input : System.Web.UI.Page
{
public string conStr = WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
protected void Buttonsubmit_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(conStr))
{
try
{
con.Open();
Response.Write("<script language ='javascript'>alert('Connection is open');</script>");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Response.Write("<script language ='javascript'>alert('Connection Problem');</script>");
}
finally
{
con.Close();
Response.Write("<script language ='javascript'>alert('Connection is close');</script>");
}
}
}
我无法连接以连接我的SQL Server数据库。运行此代码后,我收到“连接问题”。请帮忙。
答案 0 :(得分:0)
我不知道从哪里开始。
con.Open()
处设置一个断点,并确保所有参数都正确无误,或者如果异常错误没有帮助,请查看问题所在。< / LI>
醇>
也可能想看看这个: