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
my mistake, the first error was the one from below and then the one from my original post:
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 :)
When I tried to create a table in the master database, I got the same error as shown below:
Grant permission to the user to resolve the error using the code below:
After granting the permission, I am able to create a table in the master database:
But, as per this,
It’s better to create tables in a dedicated database. For more information, you can refer to this.