Tuesday, March 27, 2012

Attach Database problem

I am trying to attach a database as part of my overall application distribution.

After installing Express when my .NET app first starts it atempts to attach the database using EXEC sp_attach_db etc...

This used to work fine with MSDE 2000 but now the database is being attached as read-only. If I then use Management Studio to manually detach and attach the database it is fine.

Any ideas why this is happening please?

Hi,

is the file propably readonly (on system level) ? Do you use the same permission / login in your application as in SQL Server Managment studio ?

HTH, Jens Suessmeyer.


http://www.sqlserver2005.de

|||

Hi Jens

The .mdf and .ldf files are not set to read only.

This is happening on Windows XP.

When I run the attach command from within my code I am connected to the master db as the sa user. I am logged into Windows as an administrator user.

I have made sure that the database has been detached properly on my developement machine and the database is installed to the same path on the target machine.

Are you aware of any other reasons that could cause a db to be attached as read-only?

Thanks

Ade

|||

Odds are this is a result of the fact that SQL Express runs under Network Service rather than Local Service as was the case in MSDE. Check to see what permissions the Network Service account has on the directory where your database is located.

Mike

|||

Hi Mike

Thanks for your reply.

You were right - when I change SQL Express to run under the Local Service the problem goes away.

I can override the new default in the command line by setting the SQLACCOUNT="NT AUTHORITY\SYSTEM" parameter.

What I need to know now is why the default account has changed (and am I creating a problem by overriding it)?

The alternative is to leave the account as the Network Service but I don't know how then to set the relevant folder permissions from within my Instalshield setup (Windows XP Home and Professional)

Does anyone have any more comments on this?

Thanks again Mike

|||

Wow!

Thank you all!

I was trying to migrate a medical records system database that uses MSDE sql2000 over to SQL Express. I kept getting the "read only" errors when I tried to attach the databases to SQL Express. I was ripping my hair out!

Actually, I got the same error selecting 'local service', but selecting 'local system' WORKED!

David

No comments:

Post a Comment