用户未与 SQL 连接错误关联

发布于 2024-12-11 16:01:58 字数 5239 浏览 0 评论 0原文

我收到以下错误,该用户未与受信任的 SQL 服务器连接关联。看起来我正在使用我的 Windows 凭据(这是本地帐户)登录。我在域计算机上编写了该应用程序,并将其移至我的笔记本电脑上进行测试。笔记本电脑不在域中,我的 web.config 列在下面。我可以使用我正在使用的帐户登录 SQL Server,并拥有对数据库的完全访问权限。服务器设置为混合身份验证。我正在使用 iis 7.5 运行 Windows 7,并在 Visual Studio 2010 中对其进行调试。有人对发生的情况有任何想法吗?

Web.config

<add name="MediaTrackerConnectionString" connectionString="Data Source=myserver.full.domain.com;Initial Catalog=MediaTracker;" providerName="System.Data.SqlClient"/>

在我的页面中,我有:

           mediaConnection = new SqlConnection("user id=DOMAIN\user;" +
                      "password=XXXXXX;server=myserver.full.domain.com;" +
                      "initial catalog=MediaTracker; " +
                      "connection timeout=30");

我收到错误:

Server Error in '/' Application.

Login failed for user ''. The user is not associated with a trusted SQL Server connection.

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 ''. The user is not associated with a trusted SQL Server connection.

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 ''. The user is not associated with a trusted SQL Server connection.]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5064474
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2275
   System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +35
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) +183
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) +239
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +195
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +232
   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) +33
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +524
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +479
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +108
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126
   System.Data.SqlClient.SqlConnection.Open() +125
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +123
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +319
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +92
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1618
   System.Web.UI.WebControls.BaseDataList.GetData() +56
   System.Web.UI.WebControls.DataList.CreateControlHierarchy(Boolean useDataSource) +177
   System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +64
   System.Web.UI.WebControls.BaseDataList.DataBind() +55
   System.Web.UI.WebControls.BaseDataList.EnsureDataBound() +78
   System.Web.UI.WebControls.BaseDataList.CreateChildControls() +73
   System.Web.UI.Control.EnsureChildControls() +102
   System.Web.UI.Control.PreRenderRecursiveInternal() +42
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496

I am getting the error below, that the user is not associated with a trusted SQL server connection. It would look like I am being logged in using my windows credentials (which is a local account). I wrote the application on a domain computer and moved it to my laptop for testing. The laptop is not on the domain, my web.config is listed below. I can login into SQL server with the account I am using and have full access to the database. The server is setup for mixed authentication. I am running Windows 7 with iis 7.5 debugging it in Visual Studio 2010. Anyone have any ideas on what is going in?

Web.config

<add name="MediaTrackerConnectionString" connectionString="Data Source=myserver.full.domain.com;Initial Catalog=MediaTracker;" providerName="System.Data.SqlClient"/>

In my page I have:

           mediaConnection = new SqlConnection("user id=DOMAIN\user;" +
                      "password=XXXXXX;server=myserver.full.domain.com;" +
                      "initial catalog=MediaTracker; " +
                      "connection timeout=30");

Error I am getting:

Server Error in '/' Application.

Login failed for user ''. The user is not associated with a trusted SQL Server connection.

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 ''. The user is not associated with a trusted SQL Server connection.

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 ''. The user is not associated with a trusted SQL Server connection.]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5064474
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2275
   System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +35
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) +183
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) +239
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +195
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +232
   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) +33
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +524
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +479
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +108
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126
   System.Data.SqlClient.SqlConnection.Open() +125
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +123
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +319
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +92
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1618
   System.Web.UI.WebControls.BaseDataList.GetData() +56
   System.Web.UI.WebControls.DataList.CreateControlHierarchy(Boolean useDataSource) +177
   System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +64
   System.Web.UI.WebControls.BaseDataList.DataBind() +55
   System.Web.UI.WebControls.BaseDataList.EnsureDataBound() +78
   System.Web.UI.WebControls.BaseDataList.CreateChildControls() +73
   System.Web.UI.Control.EnsureChildControls() +102
   System.Web.UI.Control.PreRenderRecursiveInternal() +42
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

亽野灬性zι浪 2024-12-18 16:01:58

您拥有对计算机上运行的 SQL Server 实例的完全访问权限,但您可能需要映射您的帐户以从应用程序与数据库进行交互。

右键单击数据库并转到属性。转到“用户映射”,然后为您的用户帐户分配适当的权限。

编辑

听起来您可能启用了 Windows 身份验证模式,在这种情况下,您的应用程序可能会尝试使用 NETWORK SERVICE 帐户连接到数据库。从连接字符串中删除凭据并授予 NETWORK SERVICE 帐户访问数据库的权限。否则,请确保启用混合模式身份验证并使用 sa 帐户访问数据库。

You have full access to the SQL Server instance running on your computer, but you may need to map your account to interface with the database from the application.

Right click on the database and go to properties. Go to "User Mappings," and assign the appropriate priveleges for your user account.

EDIT

It sounds like you might have Windows Authentication mode enabled, in which case your application is probably trying to connect to the database with the NETWORK SERVICE account. Remove the credentials from your connection string and give the NETWORK SERVICE account permissions to acccess the database. Otherwise, make sure mixed-mode authentication is enabled and use the sa account to access the database.

翻了热茶 2024-12-18 16:01:58

这里是您需要查看的几点。只是重复一下文章所说的内容:

  1. 如果每次使用 Windows 身份验证的应用程序中都会出现此错误消息,并且客户端和 SQL Server 实例位于不同的计算机上,那么请确保用于访问 SQL Server 的帐户是域帐户。如果正在使用的帐户是客户端计算机上的本地帐户,则会出现此错误消息,因为 SQL Server 计算机和域控制器无法识别不同计算机上的本地帐户。
  2. 如果登录的用户是来自与 SQL Server 域不同的、不受信任的域的域帐户,则可能会出现此错误消息。
  3. 在尝试登录的用户帐户更改密码后,可能会立即出现此错误消息。
  4. 如果此错误消息仅偶尔出现在使用 Windows 身份验证的应用程序中,则可能是因为 SQL Server 无法联系域控制器来验证用户。
  5. 当 SSPI 不将 SQL Server 的 SPN 解释为属于本地计算机时,对于使用受信任身份验证的本地连接,此错误消息可能会一致出现。这可能是由于 DNS 配置错误或计算机具有多个名称引起的。

Here are a few points you'll want to take a look at. Just to repeat what the article says:

  1. If this error message occurs every time in an application using Windows Authentication, and the client and the SQL Server instance are on separate machines, then ensure that the account which is being used to access SQL Server is a domain account. If the account being used is a local account on the client machine, then this error message will occur because the SQL Server machine and the Domain Controller cannot recognize a local account on a different machine.
  2. this error message can appear if the user logging in is a domain account from a different, untrusted domain from the SQL Server’s domain.
  3. This error message can appear immediately after a password change for the user account attempting to login.
  4. If this error message only appears sporadically in an application using Windows Authentication, it may result because the SQL Server cannot contact the Domain Controller to validate the user.
  5. This error message can appear consistently for local connections using trusted authentication, when SQL Server’s SPN is not interpreted by SSPI as belonging to the local machine. This can be caused either by a misconfiguration of DNS, or by a machine having multiple names.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文