具体异常如下:
System.Data.SqlClient.SqlException
HResult=0x80131904
Message=在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: Named Pipes Provider, error: 40 - 无法打开到 SQL Server 的连接)
Source=.Net SqlClient Data Provider
StackTrace:
<无法计算异常堆栈跟踪>
内部异常 1:
Win32Exception: 找不到网络路径。
我的项目是用数据库连接类sqlhelper来进行数据库连接的相关操作,
登陆代码如下:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (this.password.Value.ToString().Trim() == "" || username.Value.ToString().Trim() == "")
{
Response.Write("<script>javascript:alert('请输入完整的信息');history.back();</script>");
Response.End();
}
string UserName = username.Value;
string PWD = this.password.Value;
if (this.DropDownList1.SelectedIndex == 0)
{
string SQL = "select * from Admin where UserName='" + UserName + "' and Password='" + PWD + "'";
SqlDataReader sdr = SqlHelper.ExecuteReader(SqlHelper.SqlConnection, CommandType.Text, SQL);
if (sdr.Read())
{
Session["cx"] = "管理员";
Session["PWD"] = PWD;
Session["UserName"] = sdr["username"].ToString();
Response.Redirect("Index.aspx");
}
else
{
Response.Write("<script>alert('用户名或者密码错误!');document.location=document.location;</script>");
}
}
if (this.DropDownList1.SelectedIndex == 1)
{
string SQL = "select * from Coach where Number='" + UserName + "' and Password='" + PWD + "'";
SqlDataReader sdr = SqlHelper.ExecuteReader(SqlHelper.SqlConnection, CommandType.Text, SQL);
if (sdr.Read())
{
if (sdr["issh"].ToString().Trim() == "是")
{
Session["cx"] = "教练";//权限 换为教师
Session["PWD"] = PWD;
Session["UserName"] = UserName;
Response.Redirect("CIndex.aspx");
}
else
{
Response.Write("<script>alert('信息未通过审核 请等待管理员审核.');location='javascript:history.go(-1);'</script>");
return;
}
}
else
{
Response.Write("<script>alert('用户名或者密码错误!');document.location=document.location;</script>");
}
}
if (this.DropDownList1.SelectedIndex == 2)
{
string SQL = "select * from Player where Number='" + UserName + "' and Password='" + PWD + "'";
SqlDataReader sdr = SqlHelper.ExecuteReader(SqlHelper.SqlConnection, CommandType.Text, SQL);
if (sdr.Read())
{
Response.Write(sdr["issh"].ToString());
if (sdr["issh"].ToString().Trim() == "是")
{
Session["cx"] = "球员";
Session["PWD"] = PWD;
Session["UserName"] = UserName;
Session["Name"] = sdr["Name"].ToString();
Response.Redirect("PIndex.aspx");
}
else
{
Response.Write("<script>alert('信息未通过审核 请等待管理员审核.');location='javascript:history.go(-1);'</script>");
return;
}
}
else
{
Response.Write("<script>alert('用户名或者密码错误!');document.location=document.location;</script>");
}
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("Reg.aspx");
}
protected void Button3_Click(object sender, EventArgs e)
{
Response.Redirect("Regteacher.aspx");
}
}
数据库是允许远程连接的
有没有大佬帮忙解决下,谢谢