Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

My experiences and references in SQL server
Browse by Tags · View All
SQL Server 14
#SQLServer 14
SQL Scripts 13
#TSQL 6
TSQL 6
SQL Serevr - Issues and Resolutions 3
SQL Server - Best Practises 3
SQL server - Misconceptions 3
SQL server - Statistics 2
SQL Server - Wait stats and Queues 2

Archive · View All
October 2011 8
March 2011 7
April 2011 4
May 2011 3
November 2011 3
December 2010 3
December 2011 2
June 2008 2
February 2011 2
February 2012 1

SQLZealot's Blog

Testing the Linked server connectivity From SQL server 2005

Jun 10 2008 5:04AM by Latheesh NK   

Have you ever encountered a scenario in SQL Server 2000 where you want to test the connectivity of a linked server configuration via TSQL? This was not possible easily and best handled from client side. But we have now a system stored procedure "sp_testlinkedserver" in SQL Server 2005 that allows you to test linked server connection. This stored procedure takes a linked server name as parameter, tests the connectivity and returns 0 for success & 1 for failure. You can find more details about this stored procedure in the SQL Server 2005 Books Online. Here is how a sample call can look like:

DECLARE @srvr NVARCHAR(128), 
		@retval INT;
SET @srvr = 'my_linked_srvr';
BEGIN TRY
	EXEC @retval = sys.sp_testlinkedserver @srvr;
END TRY
BEGIN CATCH
	SET @retval = sign(@@error);
END CATCH;
IF @retval <> 0
	RAISERROR('Unable to connect to server. This operation will be tried later!', 16, 2 );
  
The reason for the try...catch block is left as an exercise to readers!

Due to lack of exception handling and implementation of OPENQUERY/OPENROWSET/OPENDATASOURCE interfaces it is not possible to do it cleanly. The afore-mentioned interfaces remain the same in SQL Server 2005 also and they perform their validation at compile-time itself. So for example, if the linked server name is incorrect or the parameter to OPENROWSET is invalid you will get an error immediately. You cannot capture such errors within TRY...CATCH also. You need to enclose it in dynamic SQL so it can be caught in the same batch as the TRY...CATCH. EX:
-- below will fail at compile-time itself
-- so the try..catch never executes
BEGIN TRY
SELECT * FROM OPENQUERY(missing_server, 'SELECT * FROM sys.tables')
END TRY
BEGIN CATCH ... END CATCH

-- using dynamic sql will help since the query
-- is evaluated only when the dynamic SQL statement is executed
BEGIN TRY
EXEC('SELECT * FROM openquery(missing_server, ''SELECT * FROM sys.tables'')')
END TRY
BEGIN CATCH ... END CATCH
   
This also holds true in SQL Server 2000. Compare code below:
SELECT * FROM openquery(some_servr, 'SELECT 1')
IF @@error <> 0
	BEGIN
		PRINT 'Error'
	END
GO
EXEC('SELECT * FROM openquery(some_servr, ''SELECT 1'')')
IF @@error <> 0
BEGIN
	PRINT 'Error'
END

So the bottom-line is that you could use dynamic SQL to run the test statement against remote server and catch any errors. Now, as for your question about different domains there is lot of complexity involved depending on how you want to establish the connection. If you are using SQL logins then it is straight forward assuming the firewall or network settings allow communication between the servers. In case of Windows authentication, you may have to enable constrained delegation (Windows Server 2003) or security delegation depending on service account configurations and from where the clients connect. See BOL for discussion on these topics.


Republished from SQL - My Best Friend [58 clicks].  Read the original version here [32134 clicks].

Latheesh NK
55 · 4% · 1125
0
Liked
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]