Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check Connection before delete table 1

Status
Not open for further replies.

dk2006

MIS
Jan 19, 2006
53
US
Hi all,
I have this complex Stored Proc
1. Drip tables if exist
2. build table using SELECT INTO from Linked Servers

The problem is it will drop table before it makes connection to Linked Servers. It connection failed, I don't have tables and many application failed. I want to somehow check connectin to Linked Servers before attemp to drop and re-build table. Yes, I prefer to use DROP table than DELETE FROM for many reasons.

Can anyone point me to the right direction?

Thanks
dk
 
You could check your connection to the linked server by doing...

[tt]Select *
From OtherSever.OtherDatabase.Owner.Table
Where 1=2[/tt]

If the connection exists, you won't get an error or any data. If the connection does not exist, you will probably get an error.

Since you are using Where 1=2, this test should be really quick. Hope this helps.



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
That's exactly what I'm looking for.
Very good thinking. You defenitely get a star.

Thank you.

dk
 
How about, with error handling,

build tabletemp using SELECT INTO from Linked Servers
drop table
sp_rename tabletemp table

aside from the space considerations of having the data stored twice, it seems to me that renaming a table is a smaller overhead than hitting the linked server twice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top