login控件登陆的时候有错误

Macy0606 2011-10-11 12:16:12

using System;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.SqlServer;
using Microsoft.SqlServer.Server;
using System.Data;
using System.Data.SqlTypes;
using System.Data.Sql;
using System.Data.SqlClient;


public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection mySqlConnection = new SqlConnection();
mySqlConnection.ConnectionString = "Data Source=PC-201003241059;Initial Catalog=bs;Integrated Security=True";//"server = localhost; database = bs; integrated security=SSPI";
string SqlStr = "select * from uesrList where username = '" + username.Text + "' and pwd = '" + password.Text + "'";
SqlCommand SqlObj = new SqlCommand(SqlStr, mySqlConnection);
mySqlConnection.Open();
SqlDataReader Dr;
string Uid;
Dr = SqlObj.ExecuteReader();
if (Dr.Read())
{
Uid = Dr["id"].ToString();


System.Web.HttpContext.Current.Session["userid"] = Uid;
Session["name"] = Dr["username"].ToString();
Session["pwd"] = Dr["pwd"].ToString();
//System.Web.Security.FormsAuthentication.SetAuthCookie(Uid, true);

Dr.Close();
mySqlConnection.Close();
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "info", "window.location = 'Default2.aspx';", true);
}
else
{
Dr.Close();
mySqlConnection.Close();
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "info", "No!", true);
}

}
}

以上是的login的aspx.cs内容
前台是
用户名 username
密码 password

数据库为 manage表 id names password


运行报错
用户代码未处理sqlexception
无法打开登录 'bs' 中请求的数据库。登录失败。
用户 'PC-201003241059\Administrator' 登录失败。

求各位高人看下什么原因,谢谢
...全文
103 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
qzp000000 2011-10-11
  • 打赏
  • 举报
回复

vs上可视化连接一下,连接不上就改数据库设置啦
baby哥 2011-10-11
  • 打赏
  • 举报
回复
数据库连接字符串中不对,连接数据库失败
Macy0606 2011-10-11
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 qzp000000 的回复:]

mySqlConnection.ConnectionString = "Data Source=.;Initial Catalog=bs;Integrated Security=True";
这样试试
[/Quote]
没用
Macy0606 2011-10-11
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wknight_it 的回复:]

要想将login控件自定义相关操作

得修改配置web.config中的默认数据库驱动

http://www.cnblogs.com/chenxizhang/archive/2010/11/06/1870391.html
[/Quote]
<?xml version="1.0"?>
<!--
有关如何配置 ASP.NET 应用程序的详细信息,请访问
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
</authentication>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/"/>
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/>
</providers>
</roleManager>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
这个是现在的webconfig里的东西,怎么改
  • 打赏
  • 举报
回复
用户代码未处理sqlexception
无法打开登录 'bs' 中请求的数据库。登录失败。
用户 'PC-201003241059\Administrator' 登录失败。

网站运行的一般是ASPNET内置用户,集成登陆要求经过了Windows审核的用户(Admin)
web中一般还是基于SQL Server验证比较好,改连接串吧
mySqlConnection.ConnectionString = "Data Source=.;Initial Catalog=bs;User ID=sa;Password=123";

风骑士之怒 2011-10-11
  • 打赏
  • 举报
回复
要想将login控件自定义相关操作

得修改配置web.config中的默认数据库驱动

http://www.cnblogs.com/chenxizhang/archive/2010/11/06/1870391.html
qzp000000 2011-10-11
  • 打赏
  • 举报
回复
mySqlConnection.ConnectionString = "Data Source=.;Initial Catalog=bs;Integrated Security=True";
这样试试
三石-gary 2011-10-11
  • 打赏
  • 举报
回复
单步调试。。。你这个问题好像是没连上数据库。。
弦弦 2011-10-11
  • 打赏
  • 举报
回复
连接数据库失败,

web.config

62,025

社区成员

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

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

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

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