Unix Technical Forum

Strange error on linked server - cannot open default database

This is a discussion on Strange error on linked server - cannot open default database within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi, We have 2 servers. Server1 is a 2000 box, with SP3 (yes I know it is not up ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-01-2008, 02:53 PM
sqlgirl
 
Posts: n/a
Default Strange error on linked server - cannot open default database

Hi,

We have 2 servers. Server1 is a 2000 box, with SP3 (yes I know it is
not up to date). Server2 is a 2005 box, SP2.

I set up Server1 (2000) to have a linked server to Server2 (2005). The
reason I did this is because we are using a stored procedure on
Server2 to send mail, as we have found that using mail on 2000 doesn't
always work as advertised.

When I set up the linked server on the 2000 box, for security I just
set it up to use a SQL Server user on the 2005 box. The SQL Server
user on the 2005 box has permissions to run the stored procedure for
sending mail.

Here's the weird thing though. When calling the stored procedure on
the 2005 box from the 2000 box, sometimes we get an error that "The
default database cannot be opened", and the query does not run on the
2005 box. However, it only happens *sometimes*. Other times, the query
runs fine.

Since the problem seeemed to be with the default database, I changed
the SQL Server user on 2005 default database to the SAME database that
contains the stored procedure.

However, I just don't understand why it's even TRYING to open the
default database, since when we called the linked server we are doing
so as, and it's referencing the default database in the name:

EXEC Server2.DefaultDatabase.dbo.StoredProcedureName

However, after changing the user's default database to
"DefaultDatabase" as shown above, the query runs fine.

Why are we having this problem? That is, if I change the default
database to something other than "DefaultDatabase", then the query
doesn't run, even though the database name is referenced in the above
query??

Obviously, this is not desireable, because that means we can only run
queries that are in "DefaultDatabase", which may not always be the
case.

Thanks much

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-01-2008, 02:53 PM
Erland Sommarskog
 
Posts: n/a
Default Re: Strange error on linked server - cannot open default database

sqlgirl (tootsuite@gmail.com) writes:
> Since the problem seeemed to be with the default database, I changed
> the SQL Server user on 2005 default database to the SAME database that
> contains the stored procedure.
>
> However, I just don't understand why it's even TRYING to open the
> default database, since when we called the linked server we are doing
> so as, and it's referencing the default database in the name:
>
> EXEC Server2.DefaultDatabase.dbo.StoredProcedureName
>
> However, after changing the user's default database to
> "DefaultDatabase" as shown above, the query runs fine.
>
> Why are we having this problem? That is, if I change the default
> database to something other than "DefaultDatabase", then the query
> doesn't run, even though the database name is referenced in the above
> query??
>
> Obviously, this is not desireable, because that means we can only run
> queries that are in "DefaultDatabase", which may not always be the
> case.


When a client connects, the user is put into his default database,
unless the connect string requests a certain database. It doesn't
seem that the database in the EXEC string is added to the connection
string, and thus the default database for the user on the remote
server must be usable. That is, the user must be a valid user in
that database, and the database must exist and be online.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-01-2008, 02:53 PM
M A Srinivas
 
Posts: n/a
Default Re: Strange error on linked server - cannot open default database

On Apr 16, 9:30 pm, "sqlgirl" <tootsu...@gmail.com> wrote:
> Hi,
>
> We have 2 servers. Server1 is a 2000 box, with SP3 (yes I know it is
> not up to date). Server2 is a 2005 box, SP2.
>
> I set up Server1 (2000) to have a linked server to Server2 (2005). The
> reason I did this is because we are using a stored procedure on
> Server2 to send mail, as we have found that using mail on 2000 doesn't
> always work as advertised.
>
> When I set up the linked server on the 2000 box, for security I just
> set it up to use a SQL Server user on the 2005 box. The SQL Server
> user on the 2005 box has permissions to run the stored procedure for
> sending mail.
>
> Here's the weird thing though. When calling the stored procedure on
> the 2005 box from the 2000 box, sometimes we get an error that "The
> default database cannot be opened", and the query does not run on the
> 2005 box. However, it only happens *sometimes*. Other times, the query
> runs fine.
>
> Since the problem seeemed to be with the default database, I changed
> the SQL Server user on 2005 default database to the SAME database that
> contains the stored procedure.
>
> However, I just don't understand why it's even TRYING to open the
> default database, since when we called the linked server we are doing
> so as, and it's referencing the default database in the name:
>
> EXEC Server2.DefaultDatabase.dbo.StoredProcedureName
>
> However, after changing the user's default database to
> "DefaultDatabase" as shown above, the query runs fine.
>
> Why are we having this problem? That is, if I change the default
> database to something other than "DefaultDatabase", then the query
> doesn't run, even though the database name is referenced in the above
> query??
>
> Obviously, this is not desireable, because that means we can only run
> queries that are in "DefaultDatabase", which may not always be the
> case.
>
> Thanks much


You can make tempdb as the default database in case default database
name is changed/ default database is dropped . When client logs in
you want get an error

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:16 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com