Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem attaching a database file to my SQLServer using Integrated Security

Status
Not open for further replies.

MichelVanderbeke

Programmer
Jun 21, 2017
3
BE
Hello everyone,

I have a problem attaching a database file to my SQLServer using Integrated Security.
Depending on where my .mdf and _log.LDF files are located it works or doesn’t work.

The connectionstring in the app.config-file of a C# project is:

providerName="System.Data.SqlClient"
connectionString="Data Source=PREDATORG9-793;
AttachDbFilename = D:\_Michel Vanderbeke\Documents\Visual Studio 2017\Projects\Michels gegevens\Michels gegevens\Gegevens\Michels gegevens.mdf;
Integrated Security=true;
Connect Timeout = 30"

This way the program runs fine.

When I move the .mdf file to another location and adjust the connectionstring to:

providerName="System.Data.SqlClient"
connectionString="Data Source=PREDATORG9-793;
AttachDbFilename = C:\Test_C\Michels gegevens.mdf;
Integrated Security=true;
Connect Timeout = 30"

I get an error message:
{"Unable to open the physical file \"C:\\Test_C\\Michels gegevens.mdf\". Operating system error 5: \"5(Access denied.)\".\r\nAn attempt to attach an auto-named database for file C:\\Test_C\\Michels gegevens.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."}

Can someone help me with this error? Why can’t I put the database-files on a different location? The only difference between the two connection strings is the map where the database-files are.

Many thanks and greetings,

Michel

 
The user under which the SQL Server instance is executing requires access to the folder where the MDF file is located - that is the error you are getting.

Nothing to do with your authentication to the server.

Regards

Frederico Fonseca
SysSoft Integrated Ltd

FAQ219-2884
FAQ181-2886
 
There is a reason for the folder MSSQL puts its own master/temp etc databases, the system account of the service has access to it.

If you need to automate granting file permissions, you may use cacls.exe or icacls.exe for that:

A list of well known SIDs to use as icacls parameter is here:

eg S-1-5-20 for NT Authority/Network Service

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top