SQL Server 2012 - database in Suspect mode - unable to alter database

Chris Youngblut 1 Reputation point
2021-01-07T02:24:18.457+00:00

I have two databases on a SQL 2012 server that are in suspect mode. I am logged in as sa with sysadmin rights but i'm unable to put the database in Emergency mode or do any Alter database commands. All return a message that 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. I could possibly restore from a backup but am hoping to fix the issue. I think it occurred after a power outage that took the server down without proper shutdown. Anything i can try?

Developer technologies Transact-SQL
SQL Server Other
{count} votes

5 answers

Sort by: Most helpful
  1. Shashank Singh 6,251 Reputation points
    2021-01-08T05:46:57.403+00:00

    Both these messages do not say that DB is suspect, how did you reach to that conclusion, is it showing suspect in SSMS ?. Plus you do not seem to have permission that is why you are getting User does not have permission to alter database 'dbname', the database doe not exist, or the database is not in a state that allow access to checks. this message. You need DB owner permission and to be on safer side sysadmin permission to solve database corruption/suspect thing.

    1 person found this answer helpful.
    0 comments No comments

  2. Olaf Helper 47,436 Reputation points
    2021-01-07T07:24:19.45+00:00

    Have you reviewed the SQL Server ErrorLog for some details about the reason? On this the next step depends on.

    See also https://www.sqlskills.com/blogs/paul/checkdb-from-every-angle-emergency-mode-repair-the-very-very-last-resort/

    0 comments No comments

  3. Chris Youngblut 1 Reputation point
    2021-01-07T16:50:11.997+00:00

    When i check the logs i get the following:
    Login failed for user "sa". Reason: Failed to open the explicity specified database "dbname". [CLIENT: <local machine>]
    Error: 18456 : Severity: 14. State 38

    When i try to put into emergency mode - i get the following:

    MSG 5011, Level 14, State 7, Line 1
    User does not have permission to alter database 'dbname', the database doe not exist, or the database is not in a state that allow access to checks.
    Msg 5069, Level 16, State 1, Line 1
    Alter Database statement failed.

    0 comments No comments

  4. CathyJi-MSFT 22,396 Reputation points Microsoft External Staff
    2021-01-08T06:03:33.207+00:00

    Hi @Chris Youngblut ,

    When database in SUSPECT state, we have only 3 choices.

    (1) Do ALTER ONLINE again, order SQL Server to do a recovery again.
    (2) Give up the current database and restore the database from a backup.
    (3) Set the database status to EMERGENCY and try to repair the database.

    > Error: 18456 : Severity: 14. State 38

    State 38 means 'Login valid but database unavailable (or login not permissioned)'

    Agree with Shashank, please using below T-SQL check your database state and your SQL login permission.

    select user_access_desc, is_read_only, state_desc, is_in_standby  
    from sys.databases where database_id = DB_ID('yourdb')  
    
    select IS_SRVROLEMEMBER('sysadmin', name)  
    from sys.server_principals  
    where name = 'yourloginname'  
    

    If your database is in suspect state, and your login has admin permission. You can set the database status to EMERGENCY and try to repair the database. Please refer to the blog How to Recover MS SQL Database from Suspect Mode to get more detail information.

    Best regards,
    Cathy


    If the response is helpful, please click "Accept Answer" and upvote it, thank you.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  5. Stacy Clark 31 Reputation points
    2021-01-18T08:30:05.74+00:00

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.