skip to Main Content

I have few scripts which create some tables in some Azure Databases and these are fired up by init.sh. If I log in SSMS with the same user I am passing to the connection string and I run manually the scripts they successfully run with no problem. However, when I run my code I am getting this:

CREATE TABLE permission denied in database 'master'.

I am using the same user as the one used to run manually. This makes no sense to me. What am I missing out? I tested the code on SQL DB running in a Docker Container in a VM and everything worked fine, tables were created. The code, should not be the issue.

2

Answers


  1. Chosen as BEST ANSWER

    my mistake, the first error was the one from below and then the one from my original post:

    USE statement is not supported to switch between databases. Use a new connection to connect to a different database.
    

    USE statement doesn't work for Azure SQL databases. And since this doesn't work I think it takes as default the master and tries to create there :)


  2. When I tried to create a table in the master database, I got the same error as shown below:

    enter image description here

    Grant permission to the user to resolve the error using the code below:

    USE Master;
    GRANT CREATE TABLE TO <user>;
    

    enter image description here

    After granting the permission, I am able to create a table in the master database:

    enter image description here

    But, as per this,

    The master database is a system database – it’s not really for you to poke around in and store stuff. We usually design different backup & recovery processes for the master database as opposed to user databases.

    It’s better to create tables in a dedicated database. For more information, you can refer to this.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search