日期:2014-05-18  浏览次数:20484 次

在建立与服务器的连接时出错
SqlConnection con = new SqlConnection();
  con.ConnectionString = "server=localhost;database=user ;uid=admin;pwd=''";//本机的用户名为admin 密码为空 
  con.Open();
  string w = ud.Text.ToString();//网页用户名登录的Textbox
  string n = pw.Text.ToString();//网页用户密码
  string str = string.Format("select * from usernp where username='{0}'and userpw='{1}'", w, n);
  SqlCommand conn = new SqlCommand(str, con);
  int k = Convert.ToInt32(conn.ExecuteScalar());
  if (k > 0)
  {
  Session["check"] = 1;
  Response.Redirect("cl.aspx");
  con.Close();
  }
  else
  {
  Session["check"] = 0;
  Response.Redirect("error.aspx");
  con.Close();
  }

“/hzcl”应用程序中的服务器错误。
--------------------------------------------

在建立与服务器的连接时出错。在连接到 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 的连接)

源错误: 


行 22: SqlConnection con = new SqlConnection();
行 23: con.ConnectionString = "server=localhost;database=user ;uid=admin;pwd=''";
行 24: con.Open();
行 25: string w = ud.Text.ToString();
行 26: string n = pw.Text.ToString();
 

源文件: f:\hzcl\index.aspx.cs 行: 24 

堆栈跟踪: 


[SqlException (0x80131904): 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接)]
  System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +173
  System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +199
  System.Data.SqlClient.TdsParser.Connect(Boolean& useFailoverPartner, Boolean& failoverDemandDone, String host, String failoverPartner, String protocol, SqlInternalConnectionTds connHandler, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject, Boolean aliasLookup) +1069
  System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +606
  System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +193
  System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +502
  System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +28
  System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject