0

I have created an MSI file that installs a program. As part of the installation process, I need to create a local database using SQL Server 2016 Express on Windows 10 Enterprise. When I run the MSI, the following error occurs:

CREATE DATABASE permission denied in database 'master'.
SQL error number = 262 ==> SQL server = (local)\MYCOMPUTER --> SQL state = 1 --> Error code = -2146232060 --> SQL Error: System.Data.SqlClient.SqlError: CREATE DATABASE permission denied in database 'master'.

How can I get past this issue and create the local database? Is there a setting I need to change in SQL Server, or in my code itself?

Googling this question has told me that I need to give the user login the roles of "sysadmin" and "dbcreator", but this hasn't worked. I've disabled these roles for the user for now.

Ben
  • 31
  • 7
  • Are you running the MSI as administrator? – Edney Holder Aug 21 '19 at 15:05
  • Do you want to use Windows Credentials or a Username and Password? What account is the installation process using (and environmental variables). – jdweng Aug 21 '19 at 15:15
  • @jdweng Username and password. What do you mean by "what account" and "environmental variables"? – Ben Aug 21 '19 at 15:41
  • @EdneyHolder Running as admin hasn't made a difference, sadly. – Ben Aug 21 '19 at 15:48
  • What account were you using when you ran the MSI. A user or admin? If you ran as a scheduled task it may of been run with Sys account that doesn't have any environmental variables set. – jdweng Aug 21 '19 at 16:30

1 Answers1

0

In your script add the following

USE master;
GRANT CREATE ANY DATABASE TO <LoginName>;
GRANT CREATE TABLE TO <LoginName>;
Edney Holder
  • 1,140
  • 8
  • 22