登陆问题,web网站登陆时,在于数据库进行交互时发生错误

清朝的恒星 2019-04-01 12:55:28
具体异常如下:
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");
}
}


数据库是允许远程连接的



有没有大佬帮忙解决下,谢谢
...全文
276 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
清朝的恒星 2019-04-01
  • 打赏
  • 举报
回复
引用 1 楼 EdsionWang的回复:
连接字符串有问题,查看你的web.config文件中的连接字符串。
解决了,谢谢帮助
carryfly 2021-11-21
  • 举报
回复
@清朝的恒星 你好 在哪里查看web。conflg文件啊
正怒月神 版主 2019-04-01
  • 打赏
  • 举报
回复
先去看看 数据库 配置管理器是不是开启了。 然后看看数据库链接 的服务器名对不对。
EdsionWang 2019-04-01
  • 打赏
  • 举报
回复
连接字符串有问题,查看你的web.config文件中的连接字符串。

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧