Azure SQL Server Can't create table - sql

A couple of weeks ago, I acquired a SQL Server database and started to develop my application with it with no problems since then.
Today, out of nowhere, I got this error:
Msg 262, Level 14, State 1, Line 1
CREATE TABLE permission denied in database 'master'.
This error is shown everytime I try to create a table, I tried SELECT, it works fine. I'm trying to understand what is wrong for hours, I only have one user, which I created when I setup the database for the first time, and I checked it's permission, it shows that I have permission to create a new table.
Also, everytime I connect to it with Management Studio 2016, it asks for me to add my IP, so I know that's not the issue.
I really have no idea how to continue from here, everything I found online people talk about granting permissions which it doesn't seems to be what is happening here, since I checked my permissions.
Any other thoughts?

The error says,You don't have permission to create table in master database..try creating in your database..
You can't create table in master database in SQLAzure.Master database in SQLAzure is readonly and is there, to hold information about roles,logins..
Check out this question as well:Please explain SQL Azure "master" database

Related

Unable To Bring Online Any Database On A Server

Over the weekend my Dev server experienced a very interesting issue. I have a scripts that periodically take several databases offline, and then bring them back online again. They ran, and took all the specified databases offline, but then failed to bring them online again, the specified error message was:
Msg 5011, Level 14, State 7, Line 4 User does not have permission to
alter database 'XXX', the database does not exist, or the database is
not in a state that allows access checks. Msg 5069, Level 16, State 1,
Line 4 ALTER DATABASE statement failed.
This doesn't seem right to me as they we're run from a user account that has the following properties set:
I further validated that it wasn't a permissions issue by logging on to that server, running SSMS as an Administrator and logging in with my windows credentials (also a admin account) and executing the following SQL on the offline database:
USE [master]
GO
ALTER DATABASE [XXX] SET ONLINE
GO
With the same results...
I've looked at the SQL logs for more details about the specific error, however there are no entries associated with this issue. I can reproduce this issue on every database on this particular server. The only way I've been able to get the databases online is by de-attaching and reattaching them.
Most other stack overflow tickets involving this error message are specific to one database or a specific user account. My issue spans all databases and all admin users I've tried so far, also my issue occurred on a script that had previous worked fine on this server and account, clearly something has shifted over the weekend that is causing this query to now fail. I wonder if anyone else has experienced this issue before?
Update 1
This post talks about how file security can trigger this error message, I granted full access to the user group on one of the databases, then reran the online command, no luck. My SQL Server service is running under a service account that is part of the "Administrator" user group and has full access to all database files.
Update 2
All sorts of interesting idea's put forward here, also discussed here. Lots of commands and ideas on how to repair damaged databases with a several combinations of repair like SQL command, unfortunately none of them work in my situation, they either won't run on offline databases, or after detach and reattachment do not report any errors. Of course, there are always a number of posts simply insisting that the solution is permission based and that running: GRANT ALTER ON DATABASE will resolve all issues. For my admin user account it shouldn't make a difference, but it's a moot point as I can't even run that command on a offline database...
Finally tracked down the issue, apparently we had a completely unrelated SQL database instance on the same server in recovery mode. While it was recovering we we're unable to bring any offline instances online. Detach/re-attach would work, and we could restore the database just fine, but just not set it online.
The separate database finished recovering and we are now able to run the command without issue. I suppose in the future, if I don't care about the database that's in recovery(which I often don't) I'll following the linked steps to get rid of it, before restarting SQL Server and proceeding:
Stop SQL Server
Delete MDF + LDF
Start SQL Server
Restore (may need to drop first, comes up suspect)

"The server principal is not able to access the database under the current security context," but user isn't accessing that DB

There are a ton of threads about this error, but I can't find an answer for what I'm dealing with. I have a simple view in DB1 and a user that has permission to select from it. It's not a cross database script. Just a simple SELECT from DB1 only. The server has recently been migrated to 2016 (from 2008) by a vendor and everything was working fine until recently when I would get this error sporadically, but about not having access to DB2. That user is not looking at DB2 at all and again, no cross-database SELECT. This now has also happened to another user. I just can't figure this out. Any ideas?
Thanks!

How to delete a corrupt database from azure sql

I have tried to delete a SQL database from the azure portal. It looks like it has failed part way though. The database doesn't show up under the list of SQL servers in the Azure portal. However if I login to the server through SSMS it is still there. I now can't delete the database or create a new one with that name.
I've tried deleting the database with a query and get an error saying the database doesn't exits. If I try to create it either from the Azure portal or SSMS it gets an error saying it already exists.
I had a similar problem once, with SSL settings, where it would return that it is linked to the app even tho it wasn't, hence I was not able to delete it. After a couple of weeks of back and forward with the support, we removed it through azure resource explorer.
How to:
Once you are logged in, set read/write
In serach box find your resource
Click actions (POST/DELETE) // these should be available now since you have set read/write
Click Delete
Hopefully, this would help anyone who has any corrupted resources in Azure.

An error occurred during Service Master Key decryption

I am relatively new to SQL so will try explain as best I can.
All servers are SQL Server 2012
I currently have a database which has two Linked Servers to access two other databases.
From these 3 databases I have setup 5 view which are referenced in a stored procedure.
When trying to run the stored procedure it was failing, I opened the procedure and tried to run it manually to see what the issue was and received the below error:
Msg 33094, Level 16, State 1, Line 16
An error occurred during Service Master Key decryption
I then tried breaking it down and found that I was receiving this error when trying to reference the views that where using the Linked Servers.
I tried simple selecting the top 1000 rows of these views and strangely enough it will return the values 1 out of 5 times and give the above error the rest of the time.
I've tried Googling the issue but a lot of the issue are referenced when a database has been restored or moved, nothing of the sort has happened with mine.
it was suggested to run the below to see if there was an error and I've had none.
ALTER SERVICE MASTER KEY REGENERATE
edit:
I've also created a new accounts and relinked both servers in an attempt to test/fix the issue.
The accounts are SQL Server Authenticated accounts with db_datareader rights to the databases
Can anyone suggest what I should perhaps look at, I'm a little lost.
Thanks in advance for any help or advice.
We have the same setup and had exactly the same problem on some of our servers and we narrowed it down to a recent Windows patch, KB3004375 ("Update to improve Windows command-line auditing"). After removing this security patch, there are no more errors.
I can elaborate more if needed.

The database [dbName] is not accessible. (ObjectExplorer)

I have an issue in regards to using SQL Server 2008 R2.
I recently had an issue with my computer and therefore I had to reboot windows and had to grant permission from one user to another user (using the security feature in the properties). When giving permission initially though, it through a "Access Denied" message.
After much research, it stopped producing this error (the user which I needed to grant permission too wasn't available), which then caused another issue to occur, but this time within SQL Server. It produces this message;
The database [dbName] is not accessible. (ObjectExplorer)
This error occurs when I try to select the drop down option to see the list of tables and stored procedures of the database within SQL Server. I found an explanation for this on the following link;
http://www.microsoft.com/products/ee/transform.aspx?ProdName=Microsoft+SQL+Server&ProdVer=10.50.1617&EvtSrc=MSSQLServer&EvtID=916
And I then tried to implement like so;
USE msdb;
GO
GRANT CONNECT TO [DBName\MyName] ;
CREATE DATABASE [DBNAME] ON PRIMARY
Using a script I created (luckily before this problem occurred) it through a whole lot of messages;
Msg 15151, Level 16, State 1, Line 1
Cannot find the user 'DBName\MyName', because it does not exist or you do not have permission.
Msg 262, Level 14, State 1, Line 2
CREATE DATABASE permission denied in database 'master'.
Msg 5011, Level 14, State 9, Line 1
User does not have permission to alter database 'DBName', the database does not exist, or the database is not in a state that allows access checks.
Msg 5069, Level 16, State 1, Line 1 ...
After this bunch of errors, I have become unstuck and therefore would much be grateful if anyone could give me some feedback in regards to what I could do to resolve this issue. Cheers.
Login with sa and expand Security > Login, right click on the username and then properties,
Click User Mapping and select the DB you want the user to access and then Ok
Generally it is a bad idea to grant permissions directly to logins. You should create role objects in the database, and all permissions in the database should be assigned to the roles.
Then when moving the database to another computer (or reinstalling) the only things you have to modify are server logins and role assignments.
One possible problem is that you have two instances of the database, so you have to deactivate one instance, if you have your database opened and accessible in your server explorer in Visual studio close connexion then go to windows services and stop and restart SQL server service (MSSQL) then go to Management studio and open your database, it should be opened and you can explore tables from Management studio.
Seems the database you are trying to access do not have admin privileges. Close SSMS and open it by Run as Administrator.