p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio (http://p2p.wrox.com/forumdisplay.php?f=477)
-   -   Login failed for user 'NT AUTHORITY\NETWORK SERVICE'. (http://p2p.wrox.com/showthread.php?t=74404)

litlmike May 14th, 2009 12:36 PM

Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.
 
I receive the following error when trying to do the example from page 28 (chapter 2, 'adding a record'). I have been trying to find a solution for the last several hours, if you can help in any way that would be great. Thanks

Code:


Server Error in '/PaidTimeOffUI' Application.
 
Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.
 
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\NETWORK SERVICE'.
 
Source Error:
 
Line 43:
Line 44:        // Save the changes to the db
Line 45:        db.SubmitChanges();
Line 46:    }
Line 47:       
Source File: e:\Mirrored\MUST Save\Web Creation\Projects\PaidTimeOffSolution\PaidTimeOffUI\Default.aspx.cs    Line: 45
 
Stack Trace:
 
[SqlException (0x80131904): Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.]  System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +248  System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +245  System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2811  System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +53  System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +327  System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +2445370  System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +2445224  System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +354  System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +703  System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +54  System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +2414776  System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +92  System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +1657  System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +84  System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +1645767  System.Data.SqlClient.SqlConnection.Open() +258  System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode) +659  _Default.btnInsert_Click(Object sender, EventArgs e) in e:\Mirrored\MUST Save\Web Creation\Projects\PaidTimeOffSolution\PaidTimeOffUI\Default.aspx.cs:45  System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115  System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140  System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981
 
Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082


litlmike May 14th, 2009 12:41 PM

oh goodness, this seems to work, can someone identify if this is the correct solution that I should be taking?

Code:

<system.web>
<identity impersonate="true" userName="xxxxx" password="xxxxx" />
<.system.web>


varallov May 14th, 2009 08:40 PM

The web site uses the current user's windows identity to identify users. You should turn off anonymous access for this virtual directory and enable Integrated Windows Authentication. You can do this by opening IIS, right click on your virtual directory, select properties, click the directory security tab, click the edit button.

samjudson May 15th, 2009 07:23 AM

When creating the database connection the SQL client uses the details provided in the SQL connection string. If the connection string says to use integrated security (or trusted_Connection=Yes) then it will use the identity of the process it is currently running as.

In IIS this defaults to the NETWORK_SERVICE user, but can be overridden to 'impersonate' a different user.

You can change the user that the process runs as in a number of ways. Firstly you can edit the 'Identity' of the application pool that the web site is running as to any valid windows user.

Secondly you can set <identity impersonate="true"> in the web.config which will set it to use the user 'logged on' via the web site. This in turn will default to the anonymous user account (IUSER_<machinename>) unless you have anonymous access turned off.

Thirdly you can supply the username and password attributes with the <identity> element to get the web site to impersonate that particular user.

An alternative to all of this is to supply a username/password in the connection string [:)]

litlmike May 28th, 2009 08:11 PM

Quote:

Originally Posted by samjudson (Post 241326)
When creating the database connection the SQL client uses the details provided in the SQL connection string. If the connection string says to use integrated security (or trusted_Connection=Yes) then it will use the identity of the process it is currently running as.

In IIS this defaults to the NETWORK_SERVICE user, but can be overridden to 'impersonate' a different user.

You can change the user that the process runs as in a number of ways. Firstly you can edit the 'Identity' of the application pool that the web site is running as to any valid windows user.

Secondly you can set <identity impersonate="true"> in the web.config which will set it to use the user 'logged on' via the web site. This in turn will default to the anonymous user account (IUSER_<machinename>) unless you have anonymous access turned off.

Thirdly you can supply the username and password attributes with the <identity> element to get the web site to impersonate that particular user.

An alternative to all of this is to supply a username/password in the connection string [:)]

Thanks for the info, it is good to know my options.


All times are GMT -4. The time now is 12:39 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.