Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio
This is the forum to discuss the Wrox book ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solution by Vincent Varallo; ISBN: 9780470396865
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 14th, 2009, 12:36 PM
Registered User
 
Join Date: May 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
  #2 (permalink)  
Old May 14th, 2009, 12:41 PM
Registered User
 
Join Date: May 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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>
  #3 (permalink)  
Old May 14th, 2009, 08:40 PM
Wrox Author
 
Join Date: Jan 2009
Posts: 73
Thanks: 0
Thanked 7 Times in 7 Posts
Default

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.
  #4 (permalink)  
Old May 15th, 2009, 07:23 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
  #5 (permalink)  
Old May 28th, 2009, 08:11 PM
Registered User
 
Join Date: May 2009
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by samjudson View Post
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.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
failed for user 'NT AUTHORITY\NETWORK SERVICE' GS ASP.NET 2.0 Professional 5 March 26th, 2007 05:16 AM
user 'NT AUTHORITY\NETWORK SERVICE' GS ASP.NET 2.0 Basics 0 March 25th, 2007 10:58 AM
Login failed for user 'NT INSTANS\NETWORK SERVICE' keysersoze BOOK: ASP.NET Website Programming Problem-Design-Solution 3 April 6th, 2005 01:25 PM
login failed for user nt authority\anonymous login rj1406 Classic ASP Databases 1 October 24th, 2004 09:15 AM



All times are GMT -4. The time now is 09:44 AM.


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