2016-01-13 352 views
-5

他們。我是c#中的新手,如果對於那裏的專家來說這個問題聽起來很愚蠢,我想道歉。當我嘗試在瀏覽器的本地主機上部署我的mvc應用程序時,我不斷收到上述錯誤。我使用了IIS服務器。我通過Server exporer連接了數據庫,系統運行良好。System.Data.SqlClient.SqlException:登錄失敗,用戶'NT AUTHORITY ANONYMOUS LOGON'

它運行良好,如果我從Visual Studio運行它。當我在瀏覽器上輸入本地主機時,我得到應用程序默認登錄頁面,這是很好,但錯誤時,我提交的數據,讓我覺得它的數據庫連接問題。我已經嘗試過對此進行研究,但我還沒有找到爲我量身定製的答案。請儘快協助我,因爲我卡住了。我使用Windows身份驗證,所以請協助我,但幫助我連接使用Windows身份驗證,並指出我可以改變,以確保成功後連接數據庫密碼和用戶身份驗證。

Thanx提前!

下面是我的連接字符串

<add name="SA1Entities1" connectionString="metadata=res://*/Models.SA1.csdl|res://*/Models.SA1.ssdl|res://*/Models.SA1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=NPX4912PLUS;initial catalog=SA1;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 

的staketrace是如下:

Server Error in '/' Application. 

Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'. 

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 'NT AUTHORITY\ANONYMOUS LOGON'. 

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 'NT AUTHORITY\ANONYMOUS LOGON'.] 
    System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +110 
    System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +345 
    System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +4927 
    System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +81 
    System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +54 
    System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +451 
    System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +1667 
    System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +518 
    System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken) +767 
    System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +442 
    System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +70 
    System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +919 
    System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +114 
    System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +1631 
    System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +117 
    System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +267 
    System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +318 
    System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +132 
    System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +195 
    System.Data.SqlClient.SqlConnection.Open() +122 
    System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch(TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed) +104 
    System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext) +442 
    System.Data.Entity.SqlServer.<>c__DisplayClass1.<Execute>b__0() +16 
    System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1 operation) +229 
    System.Data.Entity.Core.EntityClient.EntityConnection.Open() +328 

[EntityException: The underlying provider failed on Open.] 
    System.Data.Entity.Core.EntityClient.EntityConnection.Open() +699 
    System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions) +168 
    System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) +64 
    System.Data.Entity.Core.Objects.<>c__DisplayClass7.<GetResults>b__5() +193 
    System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1 operation) +229 
    System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +334 
    System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0() +31 
    System.Data.Entity.Internal.LazyEnumerator`1.MoveNext() +37 
    System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source) +147 
    SA.Controllers.HomeController.Logon(user u) +1000 
    lambda_method(Closure , ControllerBase , Object[]) +139 
    System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +229 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +35 
    System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +39 
    System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +67 
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +69 
    System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +72 
    System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +386 
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +69 
    System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +38 
    System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +186 
    System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +59 
    System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29 
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +65 
    System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53 
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36 
    System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38 
    System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +44 
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +65 
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38 
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +399 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +157 
+0

從給出的信息很難說,但我猜一下,我會看看你是否[模擬](https://technet.microsoft.com/en-gb/library/cc730708(v = ws.10).aspx)打開 - 這聽起來像你在你的情況下需要它。 –

回答

2

確定這是非常簡單的,它是記錄互聯網上的許多地方,但我會走你通過它。

您遇到的基本問題是您正在運行VS,並且您擁有SQL Server帳戶,因此集成身份驗證可以正常工作,但II不會像您一樣運行 - 它將作爲特殊服務帳戶運行,並且該帳戶會執行對SQL Server沒有權限。

所以....

當您從IIS連接到SQL服務器有兩種方法可以做到這一點。

  • 首先您可以使用集成安全性。如果你這樣做,你需要做以下兩件事之一,模擬一個在你的應用程序源代碼中擁有sql server權限的用戶,或者將一個服務帳戶設置爲擁有sql server權限的用戶,以在配置中運行你的網站非法入境者。如果您進行搜索,這兩件事都是有據可查的。

  • 您還可以更改連接字符串以指定用戶。這是測試應用程序的最常見方式。查看connectionstrings.com,瞭解有關連接字符串的一些信息。

你走了。就像我說的,容易。 :)


這是不可能回答你的問題,因爲你問的是沒有意義的。

你說

它工作得很好,如果我從應用程序中運行它。

什麼應用?它是如何工作,什麼運作良好。請解釋。

當我進入瀏覽器上的本地主機...

你是什麼意思進入本地主機做?你到底在做什麼?請解釋。

讓我的默認登錄頁面這是很好的

這怎麼好?什麼是默認登錄頁面?如果您使用集成身份驗證,應該沒有登錄頁面 - 您的意思是您的應用程序的登錄頁面?如果是這樣,我們需要查看該頁面的來源。

請嘗試解釋你在做什麼,這樣我們可以有一個幫助的機會。

+1

我的意思是,當我從Visual Studio運行的應用程序運行良好,但如果我嘗試通過本地機器上的瀏覽器運行它,我通過IIS發佈它,我得到的錯誤。我得到了我的主頁,但是當我提交數據 – Etch

+0

Thnx Hogan尋求幫助時出現錯誤。不得不挖深,但我最終到了那裏。 – Etch

+0

@Etch - 很高興聽到它,在stackoverflow通常是你顯示一個答案幫助是通過投票答案,並將其標記爲解決您的問題。 – Hogan

相關問題