Creation of database in SQL Server 2008 - sql

I am unable to create a database in SQL Server 2008. This is the message that I recieve every time:
TITLE: Microsoft SQL Server Management Studio
------------------------------
Create failed for Database 'university'. (Microsoft.SqlServer.Smo)
------------------------------
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+SQL+Server&ProdVer=10.00.1600&EvtSrc=MSSQLServer&EvtID=262&LinkId=20476
What should be done?

This is related to the permission of the logged in user.
Solution 1)
Click on Start -> Click in Microsoft SQL Server 2005
Now right click on SQL Server Management Studio
Click on Run as administrator
Solution2)
check with select user_name() if you are not logged in as guest.
Add a domain account as sysadmin to SQL Express with SQLCMD
Start a command shell elevated
type SQLCMD –S (local)\sqlexpress
CREATE LOGIN [your domain account] FROM WINDOWS;
check if the login is created successfully
SELECT NAME FROM SYS.SERVER_PRINCIPALS
Grant sysadmin rights
SP_ADDSRVROLEMEMBER ‘darth\vader’, ‘sysadmin’
Reference : http://blogs.msdn.com/b/dparys/archive/2009/09/17/create-database-permission-denied-in-database-master-my-fix.aspx

You need to give the account your using permission to create databases.
You may need to login using the sa account and perform a GRANT on the user account.
GRANT CREATE DATABASE TO YourAccount;
http://msdn.microsoft.com/en-us/library/ms178569.aspx

Related

Create login with execute

I am working on a project and I have access to SQL Server as external user with limited privileges.
When I want to create a login for example with this command, I get permission denied:
CREATE LOGIN [login] WITH PASSWORD=N'test', DEFAULT_DATABASE=[master],
DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF)
However when I try to create a login with this command I can make it and also I have privileges now to enable xp_cmd shell as well:
EXECUTE('EXECUTE(''CREATE LOGIN [test5] WITH PASSWORD=N''''test'''',
DEFAULT_DATABASE=[master], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF'') AT "hostname\domain"')
EXECUTE('EXECUTE(''ALTER SERVER ROLE [sysadmin] ADD MEMBER [test5]'')
EXECUTE('EXECUTE(''ALTER SERVER ROLE [db_owner] ADD MEMBER [test5]'')
Can someone please explain why is that?
EXECUTE('string sql statement') AT "hostname\domain" == the 'string sql statement' is a pass-through command executed at the linked server "hostname/domain".
Has someone created a loop-back linked server (a linked server that points to the sql instance itself)?
Linked servers have their own security configuration/settings. If the security of the linked server is configured (for any login) to be made under the security context of a privileged login(eg. sa) then exec('') at linkedserver will be executed with way more/elevated permissions (than expected). This is a major security issue/hole.
Check the security of the linked server and change accordingly (and do you really need a loopback linked server?)

Sysadmin and sa in sql server 2000 - drop and recreate login?

A somewhat open-ended question so any information that closes the gaps in my knowledge would be appreciated.
When doing a SQL Server upgrade from 2000 to 2008 the upgrade advisor can give the following warning:
The Upgrade Advisor detected one or more user-defined login names that match the names of fixed server roles. Fixed server role names are reserved in SQL Server 2008. Rename the login before upgrading to SQL Server 2008.
I believe this is because say for example a login of 'sysadmin' in a sql server 2000 database will clash with a fixed server role of 'sysadmin' in 2008..
Is there a way to safely drop and re-create these logins or could dropping a login of say 'sa' have unintended consequences?
Repro of issue :
1) Delete the Builtin/administrator account .
2) Try to connect to SQL Server through sqlcmd or Management studio .You will get the error 18456 Level 14 State 1.
3) Assume that i have forgotten the SA password as well.
Solution:
1) Login to the server using administrator account .
2) Stop SQL Server service and start it with -m switch(single user mode) .
2) Type sqlcmd -E and hit enter .If its named instance then sqlcmd -S -E and hit enter.
4) You will see > sign
5) Commands you need to use
CREATE LOGIN [BUILTIN\Administrators] FROM WINDOWS WITH DEFAULT_DATABASE= [master], DEFAULT_LANGUAGE=[us_english]
go
6) Give sysadmin role to the login we just created
EXEC master..sp_addsrvrolemember #loginame = N'BUILTIN\Administrators', #rolename = N'sysadmin'
GO
7) You are done.Exit out of it .8) restart you SQL Server service without -m parameter.
You are done .Login again to SQL Server and reset the SA password .Save the SA password for the rainy day .
Source

Taking ownership for SQL Server Management Studio

I'm new to SQL Server 2008. I just installed SQL Server Express. I'm having trouble creating a new database, and I think I don't have permission.
I login like this, please see this screenshot:
Then I tried to create a new database and I got this:
I tried to search for some solution and this what I've got:
http://blogs.msdn.com/b/sqlexpress/archive/2010/02/23/how-to-take-ownership-of-your-local-sql-server-2008-express.aspx
But I can't download the script and the page says:
An error occurred while processing your request.
Please help. Kind regards
I resolved my problem with the following steps:
Set the instance of the SQL Service to single-user mode:
Open SQL Server Configuration Manager. Double click SQL Server Services.
Stop all SQL Server services
Right click SQL service and click Properties, in the Advanced tab, look for 'Startup Parameters'
Insert '-m;' at the beginning of the Startup Parameters value
Start the SQL service
Open SQL Server Management Studio and login with Windows authentication, you can now add user or change password of different users.
Hope this helps!
Try logging in with the sa account and grant permissions to your Windows account.
If you do not know the sa password use sqlcmd and execute the following commands:
Use Master
Go
ALTER LOGIN [sa] WITH PASSWORD=N'NewPassword'
Go
Login with the sa account and GRANT permission to the account.
USE Master;
GRANT CREATE DATABASE TO Jommel;

Grant permissions to SQL Server 2005

Iam working in ruby on rails for fetching existing tables from remote MS Sql database.Iam getting this error while trying to run the application.
ODBC::Error: 42000 (229) [Microsoft][ODBC SQL Server Driver][SQL Server]The SELECT permission was denied on the object 'TeviceDetails', database 'BObd', schema 'dbo'.: EXEC sp_executesql N'SELECT [TeviceDetails].* FROM [TeviceDetails]'
From forums and other sites i understand this is due to 'permission denied from server DB' and mentioned several solutions to rectify this.following are the solutions i got from forums.
But my problem is, i really don't know where to type/grant these privileges. (Is it in ruby console or ODBC console.If it is in ODBC console ,from where i can access this ODBC console??)
USE msdb
CREATE USER [TheUser] FOR LOGIN [TheLogin]
GO
GRANT EXECUTE ON sp_start_job TO [TheUser]
GO
SQLAgentUserRole
SQLAgentReaderRole
SQLAgentOperatorRole
The easiest place to do that is in SQL Server Management Studio, or SSMS. It's a free download from Microsoft.
http://www.microsoft.com/en-us/download/details.aspx?id=8961
You could type these into an ODBC console but you may as well get the proper tool for the job.
Please read this answer.
TSQL to grant db_datareader and db_datawriter for MS SQL Server
You can execute this once for the database.

How to unlock user account in SQL Server 2005 Management Studio?

One of user name tried login many times and failed. Sql server 2005 locked account automatically. How can I unlock user account in SQL Server 2005 Management Studio?
Bug via SSMS in SQL 2005. Only SQL 2008
I assume you know the password or can reset it. From BOL, ALTER LOGIN
ALTER LOGIN foo WITH PASSWORD = '<enterStrongPasswordHere>' UNLOCK
Tip/workaround from http://www.sqldbadiaries.com/2010/07/21/unlock-sql-user-without-changing-the-password/#ixzz2OBIJCsqv
ALTER LOGIN sqluser WITH CHECK_POLICY = OFF;
ALTER LOGIN sqluser WITH CHECK_POLICY = ON;
GO
Open Server Management Studio, connect to the server and go to the Security --> Logins item in Object Explorer. Select the login that is locked out and double-click on it. The Status page should let you re-enable the login (uncheck the "Login is locked out" box).