【问题标题】:Error in ASP.NET (Server Error in '/' Application.)ASP.NET 中的错误(“/”应用程序中的服务器错误。)
【发布时间】:2011-02-08 13:47:45
【问题描述】:

大约一个月以来,我一直在努力解决这个让我发疯的问题,所以我对自己说,让我把它发布在这个网站上,希望有人可以帮助我。

让我们进入正题

我的程序是连接到 SQL Server 2008 的 asp.net,一旦我尝试使用 Visual Studio 2008 运行该程序,它只会给出如下所示的错误

Login failed for user 'sa'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'sa'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[SqlException (0x80131904): Login failed for user 'sa'.]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4849015
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2394
   System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +35
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +144
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +342
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +221
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +189
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +185
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +31
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +433
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +499
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +65
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
   System.Data.SqlClient.SqlConnection.Open() +122
   System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection, ConnectionState& originalState) +31
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +112
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +287
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +92
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1297
   System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +95
   System.Web.UI.WebControls.ListControl.PerformSelect() +34
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
   System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e) +22
   System.Web.UI.WebControls.ListControl.OnPreRender(EventArgs e) +18
   System.Web.UI.Control.PreRenderRecursiveInternal() +80
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842

【问题讨论】:

  • @john @abat - 是的...OP 可能对该错误消息有一些理解问题...但是这种讽刺性的废话不属于 SO。要么直接回答,要么投票关闭/标记。
  • @Kev:这不是讽刺。这很有帮助。一个月不能理解“登录失败”的人需要重新考虑其中的原因。
  • 女士们,让我们都冷静...

标签: asp.net sql-server sql-server-2008 sql-authentication


【解决方案1】:

错误在文本中...您无法使用用户 SA 连接到 sql server。

检查:

  • 如果连接字符串中的密码正常
  • 如果 sql 允许 sql 登录,而不仅仅是 windows 登录
  • 如果您可以使用您传递的确切字符串从 Visual Studio 连接到 Sql 服务器

主题外评论:Windows 身份验证通常更可取...

【讨论】:

    【解决方案2】:

    您的连接字符串配置错误。您显然正在尝试使用sa 帐户(不推荐)登录到您的 SQL 服务器。您应该在 SQL 服务器中启用具有适当权限的其他用户,然后使用该用户执行连接。一旦你解决了连接字符串中的登录凭据问题,你应该没问题。

    【讨论】:

      【解决方案3】:

      问题与您的ConnectionString 有关。您使用的用户 ID 为 sa。这意味着您使用 SQL 身份验证。您还需要提供sa 用户的密码。

      如果您提供了正确的密码,您可能需要检查 SQL Server 中的 sa 是否为 enabled

      【讨论】:

        猜你喜欢
        • 2015-10-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多