Help: SQL Server

Sharing my knowlege about SQL Server Troubleshooting Skills

  • Blog Stats

    • 2,155,369 hits
  • Select GETDATE()

    February 2026
    M T W T F S S
     1
    2345678
    9101112131415
    16171819202122
    232425262728  

Archive for the ‘Error’ Category

Troubleshooting: Cannot execute as the database principal and Property Owner is not available for Database

Posted by blakhani on March 4, 2014


No one likes errors in the world. As a part of my work with Microsoft SQL Support Services, I get to see various errors, find cause and provide solution to get rid of them. Today someone reported below error to me.

Cannot execute as the database principal because the principal "dbo" does not exist, this type of principal cannot be impersonated, or you do not have permission.

This error message was caused because SQL Server was not able to find context information for the security logon we were attempting to impersonate. In this case it was “dbo”. Going with common sense, I went ahead to check the owner of the database, which is generally visible in database > right click > properties. As soon as I attempted it, I was welcomed with next error message.

image

TITLE: Microsoft SQL Server Management Studio
——————————
Cannot show requested dialog.
——————————
ADDITIONAL INFORMATION:
Cannot show requested dialog. (SqlMgmt)
——————————
Property Owner is not available for Database ‘[SQLServerHelp]’. This property may not exist for this object, or may not be retrievable due to insufficient access rights.  (Microsoft.SqlServer.Smo)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.1746.0+((KJ_RTM_QFE-CU).101005-1216+)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.PropertyCannotBeRetrievedExceptionText&EvtID=Owner&LinkId=20476
——————————
BUTTONS:
OK
—————————— 
 

Okay. This is an interesting message. Notice the exception event source is “PropertyCannotBeRetrievedExceptionText” and exception event id “Owner”. The message means that on SMO, the value of “owner” property is not available. This means something is not right with owner of the database?

Next step was to find out who the current owner (without management studio). There are multiple ways to do it.

  • sp_helpdb

image

  • sp_helpdb ‘DatabaseName’

image

  • T-SQL which is used by sp_helpdb
select name, isnull(suser_sname(sid),'~~UNKNOWN~~'), 
convert(nvarchar(11), crdate),
dbid, cmptlevel from master.dbo.sysdatabases

 

image

As we can see above, “~~UNKNOWN~~” is not something which is not expected and that’s the reason SSMS was showing exception to get owner property.

How to fix it?

Of course, change the owner of the database so that value of SID column holds valid SID. Since we are not able to use UI, we have to use sp_changedbowner (change db owner with no spaces). This has be to run in the context of the database which has problem, as shown below. I have given sa as an example for my database.

image

Root Cause/Repro of the issue

If a database is owned by a login, we would not be able to drop the login. The possible situation which I can think of are:

  • Database owned by windows login which was part of any Windows Group. And now, windows account was deleted from active directory. 
  • Database was restored and domain controller was not available to resolve the SID to a validate login.

In my repro, I was able to get into same situation by step 1.

Important: I was NOT able to reproduce the “property owner” error in SQL Server 2014 Management Studio. It doesn’t throw exception of owner property and it can be blank in the UI.

image

This also means that owner can be changed via management studio by going to Properties  > Files tab.

image

Hope you have learned something new.

  • Cheers,
  • Balmukund Lakhani
  • Twitter @blakhani
  • Author: SQL Server 2012 AlwaysOnPaperback, Kindle
  • Posted in Error, SQL Server, SSMS | Tagged: , , , , , | Leave a Comment »

    Help: How to fix error – Reason: Server is in single user mode. Only one administrator can connect at this time

    Posted by blakhani on December 6, 2013


    First of all this is not normal to start SQL Server in single user mode. So if you are reading this blog by getting this as a search result, you might be in a tough situation. In some situations, like restoring system database or during disaster recovery you may need to start SQL in single user mode.

    Okay, so you have started SQL Server in single user mode by specifying start-up parameter “m” either by net start MSSQLServer /m or via command prompt sqlservr.exe –m –sInstanceName but when you are trying to connect via any tool (SQLCMD, OSQL, SQL Server Management Studio or any other) you are welcomed by error message.

    TITLE: Microsoft SQL Server Management Studio
    ——————————
    Error connecting to ‘(local)\SQL2k8R2’.
    ——————————
    ADDITIONAL INFORMATION:
    Login failed for user ‘Contoso\demouser’. Reason: Server is in single user mode. Only one administrator can connect at this time. (Microsoft SQL Server, Error: 18461)
    For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=18461&LinkId=20476
    ——————————
    BUTTONS
    OK
    ——————————

    Error message is clear that someone “else” has made connection to SQL Server and due to /m switch, SQL is not letting you get in. Now, logically there are two ways to fix this problem.

    • Find out who is connecting before you and stop that application (difficult in real/disaster time)
    • Ask SQL Server to not to allow anyone except me.

    Second one sounds more easy. So let’s discuss that.

    If you want to know the root cause of “why its in single user mode” then go back and look for SQL Error Log and you may find something as below.

    SingleUser_01

    In above Errorlog, we can see additional start-up parameter and warning that SQL is in single user mode.

    Essentially we want to start in single use mode and no one else except you should be able to connect. Books online has explained this clearly that you can append m parameter with the client application name. Here are few example

    • Only SQLCMD should be able to connect then it would be m”SQLCMD”
    • If you want to use Management studio only then it would be m"Microsoft SQL Server Management Studio – Query".

    Let’s see it in action. I can add start-up parameter in multiple ways. My favorite is staring SQL from command line as a service, My instance name is SQL2K8R2 so below would be the command

    Net Start MSSQL$SQL2K8R2 /m”SQLCMD”

    SingleUser_02

    If you have default instance than it would be

    Net Start MSSQLServer /m”SQLCMD”

    Once you have started SQL Service in Single use mode then only SQLCMD application can connect and other connection would get error message.

    image

    Let’s see what we nave in ERRORLOG

    2013-12-06 09:13:50.08 Server      Registry startup parameters:
         -d E:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\master.mdf
         -e E:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Log\ERRORLOG
         -l E:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\mastlog.ldf
    2013-12-06 09:13:50.08 Server      Command Line Startup Parameters:
         -s "MSSQLSERVER"
         -m "SQLCMD"

    2013-12-06 09:13:50.80 spid4s      Warning ******************
    2013-12-06 09:13:50.80 spid4s      SQL Server started in single-user mode. This an informational message only. No user action is required.

    ….

    2013-12-06 09:14:32.93 Logon       Error: 18461, Severity: 14, State: 1.
    2013-12-06 09:14:32.93 Logon       Login failed for user ‘Contoso\demouser’. Reason: Server is in single user mode. Only one administrator can connect at this time. [CLIENT: <local machine>]

    It’s important to note that string after –m parameter is case-sensitive. This means that if you give sqlcmd (all lower case) then connection can’t be made. If we want to use management studio then the parameter would be –m”Microsoft SQL Server Management Studio – Query”. This is the exactly same name as in program_name when you look at sys.processes or sys.dm_exec_sessions

    Hopefully this blog would help you in making a connection to SQL Server without stopping application, changing password, disabling account as there were the tricks I have seen to get into SQL when only one connection can be made and unfortunately that’s not you.

     

    Cheers,
    Balmukund Lakhani
    Twitter @blakhani
    Author: SQL Server 2012 AlwaysOnPaperback, Kindle

    Posted in Connectivity, Error, Screenshot, Step by Step | Tagged: , , , , , | 27 Comments »