CREATE DATABASE permission denied in database 'master'. SQL Server 2012

goucqfw6  于 2023-10-15  发布在  SQL Server
关注(0)|答案(2)|浏览(145)

I had an requirement to Create Database through windows service, when first time service will run,when i am running Create Db Script from WPF application it successfully create database but same script when i am running from Windows service i am getting error "CREATE DATABASE permission denied in database 'master'.

llycmphe

llycmphe1#

The Windows service account needs to be a member of the SQL Server sysadmin role or the db_creator server role in order to create databases. Adding the below script to your script may help you.

CREATE LOGIN [NT AUTHORITY\LOCAL SERVICE] FROM WINDOWS;
EXEC sp_addsrvrolemember 'NT AUTHORITY\LOCAL SERVICE', 'sysadmin';
swvgeqrz

swvgeqrz2#

You may be running into an administrator issue.

Before opening the program, right click on it and run it as administrator.

Hopefully this should solve your problem.

相关问题