using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
/// <summary>
///SQLServer 的摘要说明
/// </summary>
public class SQLServer
{
public SQLServer()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
/// <summary>
/// 测试数据库连接
/// </summary>
/// <returns></returns>
public bool TestConncect()
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=.\\SQLExperss;Integrated Security=true; AttachDbFilename=|DataDirectory|\\Database.mdf;User Instance=true;";
try
{
conn.Open();
return (conn.State == ConnectionState.Open);
}
catch (SqlException ex)
{
return false;
}
finally
{
conn.Close();
}
}
}
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SQLServer db = new SQLServer();
bool isConncted=db.TestConncect();
Response.Write(isConncted);
}
}
以此连接显示False 错误 请大侠们教教我
单步调试,catch (SqlException ex),查看出现什么异常了。
怎么解决的。。