2011-08-22 91 views
0

我正在編譯我的asp.net應用程序,它在編譯器中正常工作。我能夠將數據插入到sql服務器數據庫。我正在使用win驗證給予IIS數據庫訪問[拒絕]

當我從IIS服務器(asp.net 4.0 ...)嘗試相同的東西時,我能夠運行該應用程序;然而,我無法將數據添加到數據庫中

這是我得到的錯誤:

Server Error in '/' Application. 

Login failed. The login is from an untrusted domain and cannot be used with Windows authentication. 

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. The login is from an untrusted domain and cannot be used with Windows authentication. 

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. The login is from an untrusted domain and cannot be used with Windows authentication.] 
    System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5050218 
    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.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +394 
    System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary values) +407 
    System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) +89 
    System.Web.UI.WebControls.FormView.HandleInsert(String commandArg, Boolean causesValidation) +377 
    System.Web.UI.WebControls.FormView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +612 
    System.Web.UI.WebControls.FormView.OnBubbleEvent(Object source, EventArgs e) +95 
    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 
    System.Web.UI.WebControls.FormViewRow.OnBubbleEvent(Object source, EventArgs e) +112 
    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 
    System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +125 
    System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +169 
    System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +9 
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +176 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563 

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1 

我到底做錯了什麼?

事件記錄器將顯示有關信息:

Event code: 3005 
Event message: An unhandled exception has occurred. 
Event time: 8/22/2011 12:27:38 PM 
Event time (UTC): 8/22/2011 7:27:38 PM 
Event ID: 0f3bf171f8a94c06940e519fde613209 
Event sequence: 19 
Event occurrence: 4 
Event detail code: 0 

Application information: 
    Application domain: /LM/W3SVC/1/ROOT-2-129585142179013397 
    Trust level: Full 
    Application Virtual Path:/
    Application Path: c:\inetpub\wwwroot\ 
    Machine name: DEV-104 

Process information: 
    Process ID: 1280 
    Process name: aspnet_wp.exe 
    Account name: DEV-104\ASPNET 

Exception information: 
    Exception type: SqlException 
    Exception message: Login failed. The login is from an untrusted domain and cannot be used with Windows authentication. 
    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) 
    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() 
    at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) 
    at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) 
    at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) 
    at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) 
    at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) 
    at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) 
    at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) 
    at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) 
    at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) 
    at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) 
    at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) 
    at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) 
    at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) 
    at System.Data.SqlClient.SqlConnection.Open() 
    at System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) 
    at System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary values) 
    at System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) 
    at System.Web.UI.WebControls.FormView.HandleInsert(String commandArg, Boolean causesValidation) 
    at System.Web.UI.WebControls.FormView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) 
    at System.Web.UI.WebControls.FormView.OnBubbleEvent(Object source, EventArgs e) 
    at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) 
    at System.Web.UI.WebControls.FormViewRow.OnBubbleEvent(Object source, EventArgs e) 
    at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) 
    at System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) 
    at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) 
    at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) 
    at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) 
    at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) 
    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 



Request information: 
    Request URL: http://localhost/Default.aspx 
    Request path: /Default.aspx 
    User host address: 127.0.0.1 
    User: MLABS\Agordon 
    Is authenticated: True 
    Authentication Type: Negotiate 
    Thread account name: DEV-104\ASPNET 

Thread information: 
    Thread ID: 1 
    Thread account name: DEV-104\ASPNET 
    Is impersonating: False 
    Stack trace: at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) 
    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() 
    at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) 
    at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) 
    at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) 
    at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) 
    at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) 
    at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) 
    at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) 
    at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) 
    at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) 
    at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) 
    at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) 
    at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) 
    at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) 
    at System.Data.SqlClient.SqlConnection.Open() 
    at System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) 
    at System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary values) 
    at System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) 
    at System.Web.UI.WebControls.FormView.HandleInsert(String commandArg, Boolean causesValidation) 
    at System.Web.UI.WebControls.FormView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) 
    at System.Web.UI.WebControls.FormView.OnBubbleEvent(Object source, EventArgs e) 
    at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) 
    at System.Web.UI.WebControls.FormViewRow.OnBubbleEvent(Object source, EventArgs e) 
    at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) 
    at System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) 
    at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) 
    at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) 
    at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) 
    at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) 
    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 


Custom event details: 

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp. 

請注意,我使用IIS 5.1

+0

嘗試直接從企業管理器使用Web配置中的憑據登錄數據庫...如果它不起作用它是認證問題。 –

+0

@prisoner連接到SQL服務器正常工作與VS –

回答

1

我認爲你必須改變你的應用程序的用戶,打開你的IIS,請在左樹中的應用,轉到操作面板並在打開的窗口中單擊基本設置。單擊連接爲按鈕選擇IIS用戶,或者創建一個具有完全訪問權的用戶,然後選擇它。

也許以下鏈接對於IIS 5.0,5.1和6.0將有所幫助。

permissions and user rights for an IIS 5.0, IIS 5.1, or IIS 6.0 Web server

How to configure Web server permissions for Web content in IIS

Default permissions and user rights for IIS 6.0

Database is read-only or asp.net account has not write permission

希望這有助於。

+0

即時通訊對不起,我沒有看到基本設置 –

+0

你正在使用哪個版本的iis? – saber

+0

版本5.1 ......... –

1

如果我正確地解釋了這種情況,那麼您沒有對SQL服務器進行身份驗證。

當您在Visual Studio中運行應用程序時,它會在您自己的憑據下運行。當它被部署到服務器上時,它將在應用程序池的憑證下運行。 IIS中的Windows身份驗證意味着應用程序代碼能夠查看您的Windows登錄信息,以告知您是誰,但無法將該信息傳遞給任何其他系統。在SQL服務器中,這意味着它期望收到一個用戶令牌,它可以對該域進行身份驗證。

因此,在本地運行應用程序時,您認爲自己是用戶,然後像您一樣向SQL發出命令,因爲它在您的安全上下文中執行。但是,在IIS中運行時,它仍然會看到您是用戶,但它會在運行它的應用程序池的安全上下文中將這些命令提交給SQL。默認情況下,這通常是本地計算機上的服務帳戶,它不會進行身份驗證跨域。

有幾種可能的解決方法,我首選的方法是將應用程序池的安全上下文更改爲在SQL中具有適當權限的域帳戶。其他一些選項是在連接字符串中包含SQL登錄憑據並啓用模擬。可能還有其他一些方法來解決它,但他們不會很容易地想到

+0

非常感謝!如何將應用程序池的安全上下文更改爲在SQL中具有適當權限的域帳戶。 –

+0

查看應用程序池時,查看IIS右側的高級設置。在該選項卡下,列出了運行該池的用戶。將該用戶添加或更改爲SQL服務器中應限制訪問數據庫的帳戶。 – Josh

+0

@josh對不起,我如何進入高級設置? –