我收到以下错误,该用户未与受信任的SQL Server连接相关联。看起来我正在使用我的Windows凭据(这是一个本地帐户)登录。我在域计算机上编写了应用程序并将其移至我的笔记本电脑进行测试。笔记本电脑不在域中,我的web.config列在下面。我可以使用我正在使用的帐户登录SQL服务器并拥有对数据库的完全访问权限。服务器设置为混合身份验证。我正在运行Windows 7,在Visual Studio 2010中使用iis 7.5进行调试。任何人对进展情况有什么想法?
的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
答案 0 :(得分:1)
您可以完全访问计算机上运行的SQL Server实例,但您可能需要将您的帐户映射到与应用程序中的数据库接口。
右键单击数据库并转到属性。转到“用户映射”,并为您的用户帐户分配相应的权限。
修改强>
听起来您可能启用了Windows身份验证模式,在这种情况下,您的应用程序可能正在尝试使用NETWORK SERVICE帐户连接到数据库。从连接字符串中删除凭据,并授予NETWORK SERVICE帐户访问数据库的权限。否则,请确保已启用混合模式身份验证,并使用sa
帐户访问数据库。
答案 1 :(得分:0)
Here是您想要了解的几点。只是重复文章所说的内容: