CREATE DATABASE permission denied in database 'master'. Sql Server - sql-server

TITLE: Microsoft SQL Server Management Studio
Create failed for Database 'myDB'. (Microsoft.SqlServer.Smo)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=14.0.17119.0+((SSMS_Rel).170517-0412)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Create+Database&LinkId=20476
ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
CREATE DATABASE permission denied in database 'master'. (Microsoft SQL Server, Error: 262)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&ProdVer=12.00.2269&EvtSrc=MSSQLServer&EvtID=262&LinkId=20476
BUTTONS:
OK
I don't have an admin account outside of 'sa'(ı dont know the password). This account deauthorize(ı can't authorize). What can I do?

PREREQUISITES:
Administrative privileges needed on Host Server.
Downtime of approximately 10 minutes needed because SQL Server would be started in ‘Single User’ mode.
PROCEDURE:
RDP to the server with the account which has ‘Admin’ rights on the Hosting Windows box. Using a service account is good idea. -> skip this if your server is a local machine
Open ‘SQL Server Configuration Manager’ :
Start>All Programs>Microsoft SQL Server 2008 (or 2005)>Configuration Tools>SQL Server Configuration
Manager
Start SQL Services in ‘Single User Mode:
Right Click on SQL Services and click ‘properties’
Go ‘Advanced’ tab then open ‘Start up Parameters’
Write ‘-m’ at the end, then click ‘OK’.
This would open a dialog box informing that SQL Services need to be restarted for this. Click ‘OK’.
Stop dependent services like SQL Agent. Restart SQL Services.
Connect to SQL instance using SQLCMD
Right Click on Command prompt, select ‘Run as Administrator’ (in Windows 2003 and lower, run as administrator is not available and not required)
Now connect to SQL instance using SQLCMD, write below command:
SQLCMD –E –S <instance name>
Now create a windows login (i.e. group account used by DB team), use below command:
CREATE LOGIN [Login_name] FROM WINDOWS WITH DEFAULT_DATABASE=[master]
GO
Now grant ‘sysadmin’ access to this newly created login, use below command:
EXEC master..sp_addsrvrolemember #loginame = 'login_name', #rolename = 'sysadmin'
GO
Restart SQL Services in multi user mode. For doing that, remove ‘-m’ from Startup parameters and restart SQL
Services.

Related

SQL Server 2012 remote restart or stop service

I want to remote restart or stop SQL server service on SSMS. When I login in a DB using sa account, the menu bar still be disabled
I looked up some information, MS seems to disable it for security reasons from SQL server 2012
If there is any possible, I can alter some system settings to do that?
So to stop/restart an SQL Server instance from Object Explorer in SSMS, you would have to met the following requirements:
1. You must have to have at least public server role on the SQL Server instance.
2. You must have the privilege to start/stop services on the server that hosts SQL Server instance. For example, add your windows user to administrator group on the server.
Also,since SA uses SQL authentication, the best you can do is issue a SHUTDOWN command to stop SQL Server.

Local SQL Server installed by other user account, how to access from new user account

SQL Server was installed on the local PC by User1.
User1 has now left the company and a new account on the PC was created called User2.
User2 cannot access the local SQL Server installation.
Is it possible for User2 to access the local SQL Server without reinstalling?
Here is the error:
Cannot connect to mydatabasename.
Login failed for user 'myuser2name'. (.Net SqlClient Data Provider)
Server Name: mydatabasename
Error Number: 18456
Severity: 14
State: 1
Line Number: 65536
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=18456&LinkId=20476
The easiest way would be to log in via the "sa" account but I expect you don't have the password to this or it isn't enabled.
If you start the server in single-user mode you will be able to add additional users without reinstalling.
This MSDN page outlines all the steps but in brief they are
Stop all services for that instance (including Sql Agent and Integration services) using "Sql Server Configuration Manager"
Open up the properties window for the Sql Server instance you need to modify.
Add an additional startup parameter "-m"
Start the service (make sure you only start the Sql Server service)
Start SSMS using "Run as Administrator"
Connect to server using windows auth.
Add login.
Remove -m parameter from service and restart all services stopped above.

Unable to create database in SQL Server 2008 R2

I have Microsoft SOL Server 2008 R2 on my server. When I am trying to open SOL Server Management Studio as administrator and creating new database, I get this error message
create database permission denied in database 'master' error 262
Also when I am adding sysadmin in login property window section in my login. Then this message appeared:
add member failed for server role 'sysadmin'
Please let me know how to add admin permission on my login and easily to create database
you need to login with SQL server authenticaton for craeting DataBase.
If you are using Windows Authentication then you need to run SQL server as Run As Adminstrator to avoid this error.
Further details Here People Having similar error
Login to your workstation as an administrator and execute the following query
EXEC sp_addsrvrolemember 'Domain\User', 'sysadmin';
CheckHere
Sql Server will not consider if you are admin to your workstation ,but you have to explicitly
make user as a sysadmin.
Intresting

SQL Server Management Studio: Database Attachment Failed

I have publish my website in IIS7. It is running in DefaultAppPool. The Identity of this app-pool is set to LocalSystem. The IIS is running and I can run the application from IIS without any problem.
Now I want to attach the database placed in inetpub's application folder:
C:\inetpub\wwwroot\EMSApplication\App_Data\ASPNETDB.mdf
I have added new logins in the SSMS which are: NT AUTHORITY\NETWORK SERVICE and IIS APPPOOL\DefaultAppPool.
But when I am trying to attach that database in the SSMS I am getting follwoing error:
TITLE: Microsoft SQL Server Management Studio
Failed to retrieve data for this request.
(Microsoft.SqlServer.Management.Sdk.Sfc)
For help, click:
http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&LinkId=20476
------------------------------ ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or
batch. (Microsoft.SqlServer.ConnectionInfo)
CREATE FILE encountered operating system error 5(Access is denied.)
while attempting to open or create the physical file
'C:\inetpub\wwwroot\EMSApplication\App_Data\ASPNETDB.MDF'. (Microsoft
SQL Server, Error: 5123)
For help, click:
http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.00.5500&EvtSrc=MSSQLServer&EvtID=5123&LinkId=20476
------------------------------ BUTTONS:
OK
By default Microsoft SQL Server Management Studio works against a Parent Instance of SQL Express, not your User Instance. A user instance is a separate instance of the SQL Server Express Database Engine that is generated by a parent instance. User instances allow users who are not administrators on their local computers to attach and connect to SQL Server Express databases. Each instance runs under the security context of the individual user, on a one-instance-per-user basis. Here is a manual from msdn How to connect to a User Instance.
I was able to do that running Management Studio As Administrator.
I had same problem.your .mdf and .ldf files don't have necessary permission.
you should add your windows account in both .mdf and .ldf files and give it full control permission.
Now you can attach your database successfully.

SQL Server 2008 R2 Express permissions -- cannot create database or modify users

Recently just upgraded to SQL Server 2008 R2 Express. When I attempt to create a database after logging in using Windows Authentication with my id myuser I receive this error:
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
CREATE DATABASE permission denied in database 'master'. RESTORE HEADERONLY is terminating abnormally Error 262
If I try to add the sysadmin role to myuser, this is the error I receive:
Add member failed for ServerRole 'sysadmin'. (Microsoft.SqlServer.Smo)
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
User does not have permission to perform this action Error 15247
If I try to add this role to my user with T-SQL, using this command,
EXEC sp_addsrvrolemember 'ziffenergy\myuser', 'sysadmin';
GO
Here is the error I receive:
Msg 15247, Level 16, State 1, Procedure sp_addsrvrolemember, Line 29
User does not have permission to perform this action.
Does anyone have any suggestions? It seems that I can't do anything with database on the local machine. Please note that I am the administrator on the Windows 7 workstation I am using, and if I try to create or modify databases and/or users on our network IT Test database server using SQL Server Management Studio, I can do that with no problem.
Coming late to the party, but I found this fantastic step-by-step guide on getting control of your SQLExpress instance if you don't have your sa password. I used this process to not only reset my sa password, but I also added my domain account to all the available server roles. I can now create databases, alter logins, do bulk operations, backups/restores, etc using my normal login.
To summarize, you use SQL Server Configuration Manager to put your instance into single-user mode. This elevates you to sysadmin when you connect, allowing you the ability to set everything up.
Edit: I've copied the steps below - kudos to the original author of the link above.
Log on to the computer as an Administrator (or Any user with administrator privileges)
Open "SQL Server Configuration Manager"
Click "SQL Server Services" on the left pane
Stop "SQL Server" and "SQL Server Agent" instance on the right pane if it is running
Run the SQL Express in single-user mode by right clicking on "SQL Server" instance -> Properties (on the right pane of SQL Server Configuration Manager).
Click Advanced Tab, and look for "Startup Parameters". Change the "Startup Parameters" so that the new value will be -m; (without the <>)
example:
from: -dc:\Program Files\Microsoft SQL.............(til end of string)
to: -m;-dc:\Program Files\Microsoft SQL.............(til end of string)
Start the SQL Server
Open your MS SQL Server Management Studio and log on to the SQL server with "Windows Authentication" as the authentication mode. Since we have the SQL Server running on single user mode, and you are logged on to the computer with Administrator privileges, you will have a "sysadmin" access to the database.
Expand the "Security" node on MS SQL Server Management Studio on the left pane
Expand the "Logins" node
Double-click the 'sa' login
Change the password by entering a complex password if "Enforce password policy" is ticked, otherwise, just enter any password.
Make sure that "sa" Account is "enabled" by clicking on Status on the left pane. Set the radio box under "Login" to "Enabled"
Click "OK"
Back on the main window of MS SQL Server Management Studio, verify if SQL Server Authentication is used by right clicking on the top most node in the left pane (usually ".\SQLEXPRESS (SQL Server )") and choosing properties.
Click "Security" in the left pane and ensure that "SQL Server and Windows Authentication mode" is the one selected under "Server authentication"
Click "OK"
Disconnect from MS SQL Server Management Studio
Open "Sql Server Configuration Manager" again and stop the SQL Server instance.
Right-click on SQL Server instance and click on "Advanced" tab. Again look for "Startup Parameters" and remove the "-m;" that you added earlier.
Click "OK" and start the SQL Server Instance again
You should now be able to log on as "sa" using the new password that you have set in step 12.
You may be an administrator on the workstation, but that means nothing to SQL Server. Your login has to be a member of the sysadmin role in order to perform the actions in question. By default, the local administrators group is no longer added to the sysadmin role in SQL 2008 R2. You'll need to login with something else (sa for example) in order to grant yourself the permissions.
In SSMS 2012, you'll have to use:
To enable single-user mode, in SQL instance properties, DO NOT go to "Advance" tag, there is already a "Startup Parameters" tag.
Add "-m;" into parameters;
Restart the service and logon this SQL instance by using windows authentication;
The rest steps are same as above. Change your windows user account permission in security or reset SA account password.
Last, remove "-m" parameter from "startup parameters";
I followed the steps in killthrush's answer and to my surprise it did not work. Logging in as sa I could see my Windows domain user and had made them a sysadmin, but when I tried logging in with Windows auth I couldn't see my login under logins, couldn't create databases, etc. Then it hit me. That login was probably tied to another domain account with the same name (with some sort of internal/hidden ID that wasn't right). I had left this organization a while back and then came back months later. Instead of re-activating my old account (which they might have deleted) they created a new account with the same domain\username and a new internal ID. Using sa I deleted my old login, re-added it with the same name and added sysadmin. I logged back in with Windows Auth and everything looks as it should. I can now see my logins (and others) and can do whatever I need to do as a sysadmin using my Windows auth login.
I have 2 accounts on my windows machine and I was experiencing this problem with one of them. I did not want to use the sa account, I wanted to use Windows login. It was not immediately obvious to me that I needed to simply sign into the other account that I used to install SQL Server, and add the permissions for the new account from there
(SSMS > Security > Logins > Add a login there)
Easy way to get the full domain name you need to add there open cmd echo each one.
echo %userdomain%\%username%
Add a login for that user and give it all the permissons for master db and other databases you want. When I say "all permissions" make sure NOT to check of any of the "deny" permissions since that will do the opposite.
I got the same problem till I found this.
I open a new query and run the following
RESTORE DATABASE <YourDatabase>
FROM DISK='<the path to your backup file>\<YourDatabase>.bak'
then right-click on Databases -> Restore Database -> select Device -> click ... -> ADD your dataset -> Click Ok

Resources