我的页面要用数据库里的信息登录,但点击登录后,提示SQL Server 不存在或访问被拒绝,但我的数据库里已经有test_project这个数据库了啊string sql;
string myConnectString ="server=localhost;uid=sa;pwd=;database=test_project";
SqlConnection myConnection = new SqlConnection(myConnectString);
myConnection.Open();///提示此行出错
sql="select id,password from user_login where username='"+ username.Text +"'";
SqlCommand myCommand = new SqlCommand(sql,myConnection);
SqlDataReader myReader = myCommand.ExecuteReader();我觉得可能是我SQL Server的问题,怎么查看我的数据库的uid是不是sa,密码是不是为空?
string myConnectString ="server=localhost;uid=sa;pwd=;database=test_project";
SqlConnection myConnection = new SqlConnection(myConnectString);
myConnection.Open();///提示此行出错
sql="select id,password from user_login where username='"+ username.Text +"'";
SqlCommand myCommand = new SqlCommand(sql,myConnection);
SqlDataReader myReader = myCommand.ExecuteReader();我觉得可能是我SQL Server的问题,怎么查看我的数据库的uid是不是sa,密码是不是为空?
你可以用netstat -an 查看1433端口是否打开
你也可以打开开始-->程序--Microsoft Sql Server-->服务器网络实用工具
然后启用WinSock代理,代理地址为127.0.0.1,代理端口为1433,这样也可以打开1433端口
记住用netstat -an 查看1433端口的开启情况
服务器:消息18452,级别 16,状态1
[Microsoft][ODBC SQL Server Driver][SQL Server] 用户“sa“登录失败。原因:未与信任SQL Server连接相关联。
检查你 数据库 "属性"--> "安全性"--> "身份验证" 是否为 "SQl Server 和 Windows"
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: SQL Server 不存在或访问被拒绝。源错误:
行 23: {
行 24: SqlConnection myConnection = new SqlConnection(myConnectString);
行 25: myConnection.Open();/////还是此句提示出错
行 26: sql="select id,password from user_login where username='"+ username.Text +"'";
行 27: SqlCommand myCommand = new SqlCommand(sql,myConnection);
源文件: d:\inetpub\wwwroot\ASPTEST\default.aspx 行: 25 堆栈跟踪:
[SqlException: SQL Server 不存在或访问被拒绝。]
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction)
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction)
System.Data.SqlClient.SqlConnection.Open()
ASP.default_aspx.add_Click(Object sender, EventArgs e) in d:\inetpub\wwwroot\ASPTEST\default.aspx:25
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
检查你 数据库 "属性"--> "安全性"--> "身份验证" 是否为 "SQl Server 和 Windows"
而且用sa在查询分析器可以登录上去,也可以操作test_project数据库里的表
string myConnectString ="server=localhost;uid=sa;pwd=;database=test_project";
将server=localhost;改成server=你的实例名称;