Share via


You don't have permission to open this file.

Question

Sunday, March 30, 2014 2:14 AM

I'm trying to add an Entity Data Model to a Project in Visual Studio 2013.

When I browse to the file to connect to it says

"You don't have permission to open this file. Contact the owner or administrator for permission."

When I go back to SQL Management Studio and check the Server Roles assigned to my user name, I'm listed as a sysadmin.

I clicked ALL the other server roles for good measure, but this does not help.

When I installed SQL Server 2012 I created another user on my computer to serve as the SQL Server Services Account for SQL Server Agent and SQL Server Database Engine.

I notice that this user shows up as the database owner for the database I'm trying to connect to, even though I was logged on using my user name when I created the database.

Thanks in advance.

All replies (3)

Sunday, March 30, 2014 9:31 AM ✅Answered

I don't know much about Entity Data Model, but if you get an error about lack of permission for opening a file (what file?), SQL Server is probably not the right place to look for file permissions. SQL Server is about managing data in databases, not files in the file system. For file-permission errors, you need to look in Windows. Or try starting Visual Studio with "Run as Administrator".

Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se


Sunday, March 30, 2014 6:07 PM

Thanks Erland.

That of starting Visual Studio with "Run as Administrator" got me past the problem of not having permission to open the file.

The file in question is the database file itself. Meaning C:/ProgramFiles/MicrosoftSQLServer/MSSQL11/MSSQL/DATA/Databasefilename.mdf

Now the problem I'm having is that it says the file is in use.

Guess I need to go into SQL Management Studio and manually close it?

Philip


Sunday, March 30, 2014 7:08 PM

Why you would open that file from Visual Studio is beyond me, but maybe it wants to attach the file to LocalDB.

The normal way to access database files is through SQL Server, so rather than point Visual Studio to the physical file, point it to the server and the database.

You should probably ask in a forum devoted to Visual Studio.

Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se