我正在尝试将ASP.NET页与SQL Server数据库连接,但是出现此错误:
System.Data.SqlClient.SqlException
HResult = 0x80131904
消息=建立与SQL Server的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (提供者:命名管道提供者,错误:40-无法打开与SQL Server的连接)
Source = .Net SqlClient数据提供程序
代码:
protected void Page_Load(object sender, EventArgs e)
{
cn.ConnectionString = "Data Source=LAPTOP-QLEMTAEI/SQLEXPRESS;Initial Catalog=Lookatme;Integrated Security=True";
cmd.Connection = cn;
cn.Open();
}
protected void Button1_Click(object sender, EventArgs e)
{
cmd.CommandText = "select * from Login where username='" + TextBox1.Text + "'and password='" + TextBox2.Text + "'";
rd = cmd.ExecuteReader();
if (rd.Read())
{
Response.Redirect("~/Index.aspx");
}
else
{
Response.Write("Error");
}
}