INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Problem attaching a database file to my SQLServer using Integrated Security

Problem attaching a database file to my SQLServer using Integrated Security

Problem attaching a database file to my SQLServer using Integrated Security

(OP)
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

RE: Problem attaching a database file to my SQLServer using Integrated Security

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
www.syssoft-int.com

FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

RE: Problem attaching a database file to my SQLServer using Integrated Security

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:
https://technet.microsoft.com/en-us/library/cc7535...

A list of well known SIDs to use as icacls parameter is here:
https://support.microsoft.com/en-us/help/243330/we...

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

Bye, Olaf.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close