Search

Flaw in sp_helpdb by TonyBell2

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 125488
Opened: 1/11/2006 12:24:11 PM
Access Restriction: Public
1
Workaround(s)
0
User(s) can reproduce this bug
Currently the master..sp_helpdb stored procedure does not take into consideration that there may be databases with no owner associated with them. When executed it returns the following error:

Server: Msg 515, Level 16, State 2, Procedure sp_helpdb, Line 53
Cannot insert the value NULL into column 'owner', table 'tempdb.dbo.#spdbdesc___________________________________________________________________________________________________________000100003401'; column does not allow nulls. INSERT fails.
The statement has been terminated.

This error is caused by the statement:

insert into #spdbdesc (dbname, owner, created, dbid, cmptlevel)
        select name, suser_sname(sid), convert(nvarchar(11), crdate),
            dbid, cmptlevel from master.dbo.sysdatabases
            where (@dbname is null or name = @dbname)


This issue can be corrected by changing the statement to read:

insert into #spdbdesc (dbname, owner, created, dbid, cmptlevel)
        select name, isnull(suser_sname(sid),'~~UNKNOWN~~'), convert(nvarchar(11), crdate),
            dbid, cmptlevel from master.dbo.sysdatabases
            where (@dbname is null or name = @dbname)
Details (expand)
Product Language
English
Version
SQL Server 2005 - Enterprise Edition (32)
Category
Management Tools
Operating System
Windows Server 2003
Operating System Language
US English
Steps to Reproduce
Not sure. We have 4 databases with a SID of 0x01050000000000051500000002137E6DE6374B24B402BA430C650000 which translates to NULL when you run sp_helpdb.
Actual Results
The following error message:

Server: Msg 515, Level 16, State 2, Procedure sp_helpdb, Line 53
Cannot insert the value NULL into column 'owner', table 'tempdb.dbo.#spdbdesc___________________________________________________________________________________________________________000100003401'; column does not allow nulls. INSERT fails.
The statement has been terminated.
Expected Results
EUPAPI_Sys_Test 107.94 MB ~~UNKNOWN~~ 10 Jul 24 2004 Status=ONLINE, Updateability=READ_WRITE, UserAccess=MULTI_USER, Recovery=FULL, Version=539, Collation=SQL_Latin1_General_CP1_CI_AS, SQLSortOrder=52, IsTornPageDetectionEnabled, IsAutoCreateStatistics, IsAutoUpdateStatistics 80
EUPAPI_UAT1 2.75 MB ~~UNKNOWN~~ 11 Jul 24 2004 Status=ONLINE, Updateability=READ_WRITE, UserAccess=MULTI_USER, Recovery=FULL, Version=539, Collation=SQL_Latin1_General_CP1_CI_AS, SQLSortOrder=52, IsTornPageDetectionEnabled, IsAutoCreateStatistics, IsAutoUpdateStatistics 80
EUPAPI_UAT2 2.75 MB ~~UNKNOWN~~ 12 Jul 24 2004 Status=ONLINE, Updateability=READ_WRITE, UserAccess=MULTI_USER, Recovery=FULL, Version=539, Collation=SQL_Latin1_General_CP1_CI_AS, SQLSortOrder=52, IsTornPageDetectionEnabled, IsAutoCreateStatistics, IsAutoUpdateStatistics 80
SBD 6.13 MB ~~UNKNOWN~~ 13 Jul 27 2004 Status=ONLINE, Updateability=READ_WRITE, UserAccess=MULTI_USER, Recovery=FULL, Version=539, Collation=SQL_Latin1_General_CP1_CI_AS, SQLSortOrder=52, IsTornPageDetectionEnabled, IsAutoCreateStatistics, IsAutoUpdateStatistics 80
Platform
 
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 1/19/2006 at 11:32 AM
Thank you for the report. This has been filed as a bug and will be fixed in a future release.
Posted by Microsoft on 1/17/2006 at 7:32 AM
Thank you for the report. This has been filed as a bug and will be fixed in a future release.
Sign in to post a workaround.
Posted by Dan Guzman on 7/24/2009 at 4:06 AM
Specify a valid database owner. For example: ALTER AUTHORIZATION ON DATABASE::Foo TO sa;