各给前辈大家好 小弟在凌晨2点给大家发帖了 希望大家能帮帮忙
这个是我建好数据库 后 运行VC.NET时候出现的错误 我是想在建立的查询分析中找到我输入的账号和密码 这样就跳转到主页 原程序为using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace txt
{
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string userName = Request.Form.Get("userName").ToString();
string userPwd = Request.Form.Get("userPwd").ToString();
Response.Write(userName);
Response.Write(userPwd);
SqlConnection con = new SqlConnection("server=.;database=login4;uid=sa;pwd=11;");
con.Open();
SqlCommand cmd = new SqlCommand("select count(*) from login4 where userName='" + userName + "'and userPwd='" + userPwd + "'", con);
int count=Convert.ToInt32(cmd.ExecuteScalar());
if (count>0)
{
Response.Redirect("main.htm");
}
else
{
Response.Redirect("loginFail.htm");
}
}
}
}
[size=16px]以下是错误提示[size=18px] [/size] [/size]
“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------
在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接)
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.SqlClient.SqlException: 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接)
源错误:
行 23: Response.Write(userPwd);
行 24: SqlConnection con = new SqlConnection("server=.;database=login4;uid=sa;pwd=11;");
行 25: con.Open();
行 26: SqlCommand cmd = new SqlCommand("select count(*) from login4 where userName='" + userName + "'and userPwd='" + userPwd + "'", con);
行 27: int count=Convert.ToInt32(cmd.ExecuteScalar());
源文件: D:\My Documents\Visual Studio 2008\Projects\txt\txt\login.aspx.cs 行: 25
堆栈跟踪:
[SqlException (0x80131904): 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接)]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +800131
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +186
System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject) +737554
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +114
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +381
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +181
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +173
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +357
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +30
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +424
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +494
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +82
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105
System.Data.SqlClient.SqlConnection.Open() +111
txt.login.Page_Load(Object sender, EventArgs e) in D:\My Documents\Visual Studio 2008\Projects\txt\txt\login.aspx.cs:25
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436
--------------------编程问答-------------------- 在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败
注意这句话
请运行 SQL Server 外围应用配置器工具。为 TCP/IP 和 Named Pipes 都启用远程连接。 --------------------编程问答--------------------
顶LS,另外补充一下检查一下你自己的防火墙设置. --------------------编程问答-------------------- 能具体点吗 TCP/iP 怎么启动远程连接 我对对防火墙的设置一点都不懂 谢谢了 --------------------编程问答-------------------- 你没装sql吗
,sql里边就有呀,配置工具 --------------------编程问答-------------------- 你的sqlserver服务启动了没? --------------------编程问答-------------------- mark
补充:.NET技术 , C#