Home All Groups Group Topic Archive Search About

Problem in sysdatabases



Author
4 Dec 2008 3:45 PM
Simon
I get the following error message when I try and loop through all databases
to perform a query using sp_MSforeachdb.

'Could not locate entry in sysdatabases for database 'OrtusSearch'. No entry
found with that name. Make sure that the name is entered correctly.'

However where I run the below code I get no results.

select * from sysdatabases
where name = 'ortussearch'

I have an entry in sysdatabases for an ortussearch.com database. I don`t
understand why I am getting the above situation. Any thoughts ?

Author
4 Dec 2008 4:38 PM
Tibor Karaszi
Seems like sp_MSforeachdb doesn't handle databases with names that
doesn't confirm to standard identifiers. This is always the risk you
take when using non-supported features (like sp_MSforeachdb). I
suggest you use the source for for this proc as base for your own
version which does handle non-standard identifiers as database names.
Of course, if the database didn't have that stupid name in the first
place, you wouldn't have this problem (best practice is to follow
rules for standard identifiers).

Show quoteHide quote
"Simon" <Si***@discussions.microsoft.com> wrote in message
news:4AF256DA-4C2A-4095-9520-DA4E917F59A8@microsoft.com...
>I get the following error message when I try and loop through all
>databases
> to perform a query using sp_MSforeachdb.
>
> 'Could not locate entry in sysdatabases for database 'OrtusSearch'.
> No entry
> found with that name. Make sure that the name is entered correctly.'
>
> However where I run the below code I get no results.
>
> select * from sysdatabases
> where name = 'ortussearch'
>
> I have an entry in sysdatabases for an ortussearch.com database. I
> don`t
> understand why I am getting the above situation. Any thoughts ?
Are all your drivers up to date? click for free checkup

Author
5 Dec 2008 1:39 AM
Tom Cooper
At least in most cases, you can use sp_MSforeachdb with non-standard names.
You just have to make sure that the queries you are having sp_MSforeachdb
build are correct.  sp_MSforeachdb just blindly replaces each occurance of ?
with the name of the database.  So if you do,

Create Database [very bad database name]

Then
sp_MSforeachdb 'Print ''?'''
will work just fine.

But
sp_MSforeachdb 'Select ''?'', count(*) From ?.dbo.sysobjects'
will give you an error because it will try to execute
Select 'very bad database name', count(*) From very bad database
name.dbo.sysobjects
which is, of course, not legal.

However, you can do
sp_MSforeachdb 'Select ''?'', count(*) From [?].dbo.sysobjects'
because that executes
Select 'very bad database name', count(*) From [very bad database
name].dbo.sysobjects
which is legal.

If you run the above tests, don't forget to
Drop Database [very bad database name]
when you are done, and I agree 1000% with Tibor that you should always use
standard names.

Tom

Show quoteHide quote
"Tibor Karaszi" <tibor_please.no.email_kara***@hotmail.nomail.com> wrote in
message news:Onww%236iVJHA.5032@TK2MSFTNGP05.phx.gbl...
> Seems like sp_MSforeachdb doesn't handle databases with names that doesn't
> confirm to standard identifiers. This is always the risk you take when
> using non-supported features (like sp_MSforeachdb). I suggest you use the
> source for for this proc as base for your own version which does handle
> non-standard identifiers as database names. Of course, if the database
> didn't have that stupid name in the first place, you wouldn't have this
> problem (best practice is to follow rules for standard identifiers).
>
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://sqlblog.com/blogs/tibor_karaszi
>
>
> "Simon" <Si***@discussions.microsoft.com> wrote in message
> news:4AF256DA-4C2A-4095-9520-DA4E917F59A8@microsoft.com...
>>I get the following error message when I try and loop through all
>>databases
>> to perform a query using sp_MSforeachdb.
>>
>> 'Could not locate entry in sysdatabases for database 'OrtusSearch'. No
>> entry
>> found with that name. Make sure that the name is entered correctly.'
>>
>> However where I run the below code I get no results.
>>
>> select * from sysdatabases
>> where name = 'ortussearch'
>>
>> I have an entry in sysdatabases for an ortussearch.com database. I don`t
>> understand why I am getting the above situation. Any thoughts ?
>
Author
5 Dec 2008 6:45 AM
Tibor Karaszi
Good catch, Tom!

Show quoteHide quote
"Tom Cooper" <tomcooper@comcast.no.spam.please.net> wrote in message
news:%23tGzSpnVJHA.1184@TK2MSFTNGP05.phx.gbl...
> At least in most cases, you can use sp_MSforeachdb with non-standard
> names. You just have to make sure that the queries you are having
> sp_MSforeachdb build are correct.  sp_MSforeachdb just blindly
> replaces each occurance of ? with the name of the database.  So if
> you do,
>
> Create Database [very bad database name]
>
> Then
> sp_MSforeachdb 'Print ''?'''
> will work just fine.
>
> But
> sp_MSforeachdb 'Select ''?'', count(*) From ?.dbo.sysobjects'
> will give you an error because it will try to execute
> Select 'very bad database name', count(*) From very bad database
> name.dbo.sysobjects
> which is, of course, not legal.
>
> However, you can do
> sp_MSforeachdb 'Select ''?'', count(*) From [?].dbo.sysobjects'
> because that executes
> Select 'very bad database name', count(*) From [very bad database
> name].dbo.sysobjects
> which is legal.
>
> If you run the above tests, don't forget to
> Drop Database [very bad database name]
> when you are done, and I agree 1000% with Tibor that you should
> always use standard names.
>
> Tom
>
> "Tibor Karaszi" <tibor_please.no.email_kara***@hotmail.nomail.com>
> wrote in message news:Onww%236iVJHA.5032@TK2MSFTNGP05.phx.gbl...
>> Seems like sp_MSforeachdb doesn't handle databases with names that
>> doesn't confirm to standard identifiers. This is always the risk
>> you take when using non-supported features (like sp_MSforeachdb). I
>> suggest you use the source for for this proc as base for your own
>> version which does handle non-standard identifiers as database
>> names. Of course, if the database didn't have that stupid name in
>> the first place, you wouldn't have this problem (best practice is
>> to follow rules for standard identifiers).
>>
>> --
>> Tibor Karaszi, SQL Server MVP
>> http://www.karaszi.com/sqlserver/default.asp
>> http://sqlblog.com/blogs/tibor_karaszi
>>
>>
>> "Simon" <Si***@discussions.microsoft.com> wrote in message
>> news:4AF256DA-4C2A-4095-9520-DA4E917F59A8@microsoft.com...
>>>I get the following error message when I try and loop through all
>>>databases
>>> to perform a query using sp_MSforeachdb.
>>>
>>> 'Could not locate entry in sysdatabases for database
>>> 'OrtusSearch'. No entry
>>> found with that name. Make sure that the name is entered
>>> correctly.'
>>>
>>> However where I run the below code I get no results.
>>>
>>> select * from sysdatabases
>>> where name = 'ortussearch'
>>>
>>> I have an entry in sysdatabases for an ortussearch.com database. I
>>> don`t
>>> understand why I am getting the above situation. Any thoughts ?
>>
>
>

Bookmark and Share