2011-08-22 123 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对不起,我如何进入高级设置? –