Cannot add database to Visual Studio

  • Hello:

    I am using SQL Server Express 2017 with Visual Studio Professional 2017. I installed SQL Server in mixed mode.

    I have a database that I created in SQL Server, with a few tables. It is located on a network drive so that it is properly backed up, rather than storing on my local hard drive. Perhaps this is a problem?

    I am trying to add the database (ResourcePlanning.mdf) to Visual Studio. I am going to Server Explorer and Right-clicking Data Connections / Add Connection... Then selecting Microsoft SQL Server Database File / Continue and selecting the actual file via Browse. I have chosen both Windows Authentication and SQL Server Authentication options.

    The error I am continually getting is: You don't have permission to open the file. Contact the owner or an administrator to obtain permission.

    The problem is, I am the owner, and everything was created locally on my PC. SQL Server is installed on the same PC as Visual Studio. As I said, I placed the database file on a network path called \\w2012\Users\Steve A\MSSQL\DATA. This path has full permissions, as does the PC. I also have the correct local administration rights on my user account.

    I have tried to move this file over to a local C-drive folder, and this too fails, saying I need permission to perform this action, that I require permission from the computers administrator to make changes to this file.

    If I right-click the mdf file and select Properties / Security, I am told that I must have read permissions to view the properties of this object.

    Strangely, I created the file under the same login as I am trying to connect and potentially relocate with.

    Please let me know your thoughts on the matter.

    Much Thanks!

    Steve Anderson

  • It sounds like there are multiple issues here.

    First, where is the SQL Server service running that has this database, on your computer or on a server?

    Second, when you say the database is "on a network drive so it is properly backed up", a file system level backup is not adequate protection for a database.  Please make sure that BACKUP DATABASE command or a third party tool that performs database backups is used on a regular basis instead of file backups.
    https://docs.microsoft.com/en-us/sql/t-sql/statements/backup-transact-sql

    Third, you say everything "was created locally on my PC", but you say the database file is on a network share.  Was the file created in SQL Server on your computer, detached, then moved to the network share, and then reattached to another SQL Server, or how did this file move?

    Fourth, file permissions across a network share are based on the permissions granted through the share and on the server's local file system, not on who originally created the file and where it was created.  Check with an admin to find the permissions for that network folder.

    Fifth, when you say you are adding the database to Visual Studio, do you mean you are adding a reference to the database in a Visual Studio project?  Some clarification may be needed here.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply