Skip to content Skip to sidebar Skip to footer

Access Denied CREATE DATABASE LocalDB

I installed SSMS 18. I installed a new LocalDB instance by choosing it from the SQL Server Express 2017 installation as it is not yet included in the SSMS 18 installation. After in

Solution 1:

This error is due to a bug in the file creation path in SQL Express 14.0.100. Follow these steps if you are affected:

  1. Close SSMS and any running instances of SQL Server in Task Manager > Processes including SQL Server Telemetry and SQL Server Client NT related tasks.
  2. Navigate to %LocalAppData%\Microsoft\Microsoft SQL Server Local DB\Instances\ in Windows Explorer.
  3. Remove any local instances you installed like MSSQLLocalDB.
  4. Open your favorite CLI (like Command Prompt) and use these sqllocaldb commands. If it says the commands cannot be executed because the instance MSSQLLocalDB does not exist, continue to the next step.

    sqllocaldb stop MSSQLLocalDB

    sqllocaldb delete MSSQLLocalDB

  5. Update your locally installed SQL Server with the latest Cumulative Update https://www.microsoft.com/en-us/download/confirmation.aspx?id=56128. You can see an overview of updates in the Update Center for Microsoft SQL Server on Technet: https://technet.microsoft.com/en-us/library/ff803383.aspx.

  6. After a succesful update, use the sqllocaldb create command.

    sqllocaldb create "MSSQLLocalDB"

  7. Your CLI should prompt that it has created a localdb with version 14.0.300 or higher:

LocalDB instance "MSSQLLocalDB" created with version 14.0.3223.3.

If you successfully updated the local db instance but you are receiving this error after: SqlException: 'Cannot create file 'C:\Users\%USERNAME%\Database.mdf' because it already exists., please remove the file in the specified path and try again.


Solution 2:

I can't see the images due my shop's policies, but I think that you can achieve your goal in 2 ways.

In SSMS right click the server name and select properties, then go to "database settings" there's a section named "Database default locations" modify to meet your requirements.

As a second option is to specify the datafiles explicity like:

CREATE DATABASE [test]
  ON  PRIMARY 
( NAME = N'test', FILENAME = N'c:\mypath\test.mdf' , SIZE = 8192KB , FILEGROWTH = 65536KB )
 LOG ON 
( NAME = N'test_log', FILENAME = N'c:\mypath\test_log.ldf' , SIZE = 8192KB , FILEGROWTH = 65536KB )

Post a Comment for "Access Denied CREATE DATABASE LocalDB"