Can't create SQL Server DB via SSMS - error 262

  • I'm trying and failing to create a SQL Server database.

    I first tried to create it via VS 2017 but that gave me Error 40 "Could not open a connection to SQL Server".

    Googling that error message, I found advice to use SQL Server Management Studio, so I duly installed v17.2 of SSMS.

    SSMS's Object Explorer has this nice option tree with nodes "Databases", "Security", "Server Objects" etc. I did the common-sense thing:

    Right-clicked "Databases"
    Chose "New Database"
    Entered a suitable name into "Database name"

    ...and pressed OK, whereupon I got the attached message.

    A bit more Googling, and I found advice that one should have Admin privileges (I'm on Windows 10). I prefer to work with a non-admin privileges, but OK, and I made myself an administrator. However, I got the same error message (even after restarting laptop).

    I then tried MS's instructions here on creating a DB via a Transact-SQL window in SSMS. However, I again got Error 262.

  • You need to have permissions on the SQL Server instance, not on your local machine (the permmissions on your local machine are totally different to that on the instance).

    To CREATE a database you need to either have the Server Role sysadmin or dbcreator, or been granted the CREATE ANY DATABASE permission (any other permissions I've missed?)

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • Thom A - Thursday, October 12, 2017 4:48 AM

    You need to have permissions on the SQL Server instance, not on your local machine (the permmissions on your local machine are totally different to that on the instance).

    To CREATE a database you need to either have the Server Role sysadmin or dbcreator, or been granted the CREATE ANY DATABASE permission (any other permissions I've missed?)

    To add to Thom's point, the login you use to connect to SQL Server must have a server role he lists.  If you have multiple accounts to your Windows 10 machine and you want to be able to create a database with either one, you'll need to give SQL Server privs to both.  Yes, you could stick with only your primary account, but it's a good idea to leave yourself another way in, just in case something bad happens to your primary account.

    The alternative to this is, if SQL Server is running in mixed mode authentication, to login with a SQL Server login instead of a Windows login.  It would need the same privs to be able to create a database.

  • Thank you for the replies. I've had a quick look to see if there's a step-by-step guide to how to do these things, but I can't find one. Is there one that anyone knows of?

  • ktrammen - Friday, October 13, 2017 2:46 AM

    Thank you for the replies. I've had a quick look to see if there's a step-by-step guide to how to do these things, but I can't find one. Is there one that anyone knows of?

    To do what, exactly? Change the permission/role of a Login?

    There are two way (GUI and non-GUI (T-SQL).
    GUI:

    1. In SSMS, log in as account that can administer Login Permissions.
    2. Expand the Security Node in the Object Explorer
    3. Expand the logins Node
    4. Right Click the Login you wish to add the permission to and click Properties.
    5. Go to the Server Roles Pane or Securables Pane.
    6. Tick the permissions you want.
    7. Click Ok.

    Non-GUI (T-SQL):

    1. In SSMS, or your preferred query interface with SQL Server, log in as an account that can administer Login Permissions.
    2. Run the following SQL, replacing the Role and Login with the Role and Login name, or the permission (replaceable sections underlined)

    ALTER SERVER ROLE [sysadmin] ADD MEMBER [YourLogin];
    GO
    --Or, for permissions:
    GRANT CREATE ANY DATABASE TO [YourLogin];
    GO

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply