views:

905

answers:

4

Hi all,

I am having an odd problem with my SQL Server express 2005 DB. It is running on a 2003 server. With VS2005 I can access the db without any problem. But when I try and run the application I get:

 Cannot open user default database. Login failed.  Login failed for user 'NT AUTHORITY\NETWORK SERVICE'......... .ldf may be incorrect.

I have ensured that NETWORK SERVICE has full access to the website folder and all it sub folders.

I have noticed that when I look at the properties of App_Data it has a gray tick on the read only. The .MDF file is not read only but I can not remove this gray tick. I have tried just clicking it till its gone and applying changes, I have tried ATTRIB . -r but nothing seems to change it.

I am very confused.

Jon

A: 

The difference isn't related to ACLs on the folder but to that fact that the security context is mapped to a user in the DB. Your DB will have a mapping for your user account probably to dbo.

If the Network Service account is going to use the DB you need to create a user in the db to map to Machine account.

AnthonyWJones
How do I do that with SQL Server Express?
Jon
+1  A: 

Are you actually using an instance of SQL Server Express, or just using a database file in the App_Data folder?

If you are using an instance of SQL Server and you have SQL Server Management Studio Express installed, you would do something like this to give the "Network Service" account access to the database (thinking about it, you should be able to point Management Studio at the mdf in the App_Data folder as well, and do the same thing):

  1. Open SQL Management Studio, connect to your database and open it in the Object Explorer.
  2. At the Server level (MachineName\SQL Express) expand the "Security" section - check the user's not already in the "Logins" section below that.
  3. If not, Right-click on "Logins", "New Login..."
  4. Ensure that the login type is set to "Windows authentication", you can then either:
    1. Hit "Search...", then "Advanced..." then "Find now", Double click on "NT Service", "Ok" the next dialog.
    2. Just type "NT Authority\Network Service" into the "Login name:" box.
  5. Then, in the "User Mapping" page (Selected from the left-hand pane), put a Tick next to the database that you want this user to access.
  6. If you have database roles (for example if this database has the default ASP.NET membership/roles/profile tables etc installed), make sure you give the user the correct role - for example "aspnet_Membership_BasicAccess".

I hope that helps.

Zhaph - Ben Duguid
A: 

I'd guess you are running a non-english operating system.

Somehow, for whatever reasons, the login name for the network service is sometimes localized when the OS is translated into other languages.

Now a lot of programs expect the login name to be hard coded to "NT AUTHORITY\NETWORK SERVICE" - in a German version of Windows for example the name of the account is "NT-AUTORITÄT\NETZWERKDIENST". So your program is looking for the english name, can't find it, and shows an error.

Even some Microsoft programs run into this trap and show errors like this when installed!

Sam
+1  A: 

Just had this problem. We were using a database file in the App_Data folder.

"it seems I had the DB still opened inside my IDE (Visual Web Developer Express), in the database explorer. Right-clicking the database and selecting "close connection" fixed it."

(thanks to asp.net forums)

Spongeboy