Attached DB in SQL Server Management Studio to copy a table and now Web app cannot access DB

StackOverflow https://stackoverflow.com/questions/20478701

  •  30-08-2022
  •  | 
  •  

Question

In order to copy a table's data to a new table with additional fields the DB was attached in SQL Server Management Studio. Once the data was copied to the new table and the old table was dropped, the DB was detached. The DB was then opened in the development environment with Visual Studio and was accessible from the Server Explorer Data Connections. However, now the application cannot open the DB when running on the web server and gives an error saying: Cannot open user default database. Login failed. Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.

The web.config application connection string is:

<add name="ApplicationServices" connectionString="Data Source=.\SQLEXPRESS; AttachDbFilename=|DataDirectory|\ASPNETDB.mdf; Integrated Security=True; Connect Timeout=30; User Instance=True;" providerName="System.Data.SqlClient"/>

I have read over 30 post on this type of error and everything I tried from the suggestion I found did not help. NT AUTHORITY\NETWORK SERVICE in in both the server's users and the DB's users with dbo.owner rights and the app pool for the web server is set to use NETWORK SERVICES.

I am guessing that maybe SQL Server Management Studio made some changes to the DB when it was attached that are effecting the security access rights for the web server application, but not for direct data connections but for the life of me, I can not find what that may be.

The application is being developed with Visual Studio 2013 for Web using a local IIS 7 server as localhost and SQLEXPRESS for the database server. The application development process has been going along fine up till now. However, at this point development has come to a halt and I am dead in my tracks until I can get this resolved. Any help would be appreciated!

Thanks in advance! David

Était-ce utile?

La solution

Are you sure there are no orphaned users?

http://technet.microsoft.com/en-us/library/ms174378.aspx

-- Detect any orphans
EXEC sp_change_users_login 'Report';

If you already created server login named 'Mary' on SQL Express, use the following command to remap.

-- Remap to same existing login
EXEC sp_change_users_login 'Auto_Fix', 'Mary';

You can use this optional syntax to create the login with a password.

-- Remap to new login
EXEC sp_change_users_login 'Auto_Fix', 'Mary', NULL, 'B3r12-3x$098f6';
GO

In a nutshell, you can use SSMS to manage that SQLEXPRESS server. Poke around and make sure the logins and users are mapped correctly. You can even test if you have the Trusted login credentials.

If this still does not work, please post back to me.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top