Unable To Bring Online Any Database On A Server - sql

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)

Related

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.

Azure SQL Server Can't create table

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

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 process could not execute 'sp_replcmds' on 'database_name'

I got an error message in my Log Reader Agent:
The process could not execute 'sp_replcmds' on 'Database Name'.
I created another agent profile with a large query timeout and a min value to batch, but it still doesn't work.
Can someone help me?
I'm using SQL Server 2008 and I'm trying to do a replication between databases on different servers.
It could be possible that owner of the database could be someone other than what you have permissions for. Below there's a simple command to change ownership...if you have the rights to do so.
--TSQL Code--
USE PublishedDatabase
GO
EXEC sp_changedbowner 'sa'
GO
There are a lot of things that can cause this error (which include, but is not limited to):
The database has been publication disabled
The account trying to run the log reader agent doesn't have the ability connect to the publisher server
The account trying to run the log reader agent doesn't have permission to run sp_replcmds
In my experience, there's a little more to the error in the replication monitor. Is this the case for you?
This could be due to Owner is not set for the database.
You can check by right clicking on database then choose Property and go to File Table and the Owner selection should be there.

sql db problem with windows authentication

Have a SQL Server 2008 db which I connect to the Windows Authentication .. has worked good for 7-8 months .. but now when I come to work today it no longer worked to connect, without that I had done something
Error message was:
Can not open user default database. Login failed.
Login failed for user 'Jimmy-PC \ Jimmy'.
where the first is the computer name and the second is the user. The problem seems to be that it tries to connect to the default database. Have tried to change it without success .. I do not have sql server management tools for sql 2008 but only to 2005, someone who has similar experience? who have not touched anything said over the weekend and it worked last Friday without any problems.
The user's default database is offline. the thing that changed since yesterday is that your database had failed, for whatever reason.
You need to log in with a different account, one that does not have a default database, and inspect the state of the database. If you do not have such an account, then you can use an administrator account. If the administrators group is not granted login into SQL Server then see this article Troubleshooting: Connecting to SQL Server When System Administrators Are Locked Out.
Once you can log in, the only tool you need is sqlcmd.exe, which is installed on your machine. Look into sys.databases, the state_desc column will tell if a database is offline. You can try a to ALTER DATABASE ... SET ONLINE and see if it recovers, but that would be unlikely. Your best choice will be to apply your disaster recovery plan and restore the database from the backups you keep for it.
It is strange that it just stopped working. Have you checked the status of the user's default database? Make sure the database exists and is online.
To find the user's default database run the following command using sqlcmd.exe
select dbname from syslogins where name = 'Jimmy-PC \ Jimmy'
I have seen this error when recovering a system and the user's default database hadn't been restored yet and another time when a database was in "Recovery" mode.
I would also make sure that the windows account is not disabled.
If you find that you need to change the user's default database you can use a T-SQL command, see the following question:
How do I set the default database in Sql Server from code?