Click here to Skip to main content
13,408,284 members (40,407 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Of great importance is the added fact that these instances are linked as servers and they show the proper property as such in "Linked Servers" where each's catalog can be viewed.

The problem for me is that I can't specifically write a statement like this:
SELECT * FROM [COMPUTER_A\INSTANCE_01].[knowndatabase].[dbo].[knowntable]

Given the fact that INSTANCE_01 is not currently under the "USE" control within the executing interface of ssmse. Nor can I do the general sys.all_objects type of query in a loop using that same [COMPUTER_A\INSTANCE_01].sys.all_objects "expectation".

Is this question clear enough?


An idea:
DECLARE @nullscript varchar(4000)
SET @nullscript = 'sqlcmd -S COMPUTER_A\INSTANCE_01 '
EXEC xp_cmdshell @nullscript

(to view what databases are now available):
SELECT * FROM sys.master_files WHERE data_space_id = 1

(And unfortunately unfruitful next to test):

DECLARE @nullscript2 varchar(4000)
SET @nullscript2 = 'sqlcmd -S COMPUTER_A\INSTANCE_02 '
EXEC xp_cmdshell @nullscript2

(Get the INSTANCE_01 tables .. drat):
SELECT * FROM sys.master_files WHERE data_space_id = 1

No change of the INSTANCE from _01 to _02

Posted 25-Oct-12 10:40am
Updated 26-Oct-12 10:47am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The solution:

There is no solution only a workaround. SSMSE will not allow another instance to be addressed after initializing a particular server, outside of committing to the use of the interface button via mouse.

A workaround to circumvent ssmse interface altogether is of the form, after sp_addLinkedServer is deployed,

EXECUTE xp_cmdshell 'sqlcmd -S COMPUTER_A\INSTANCE_01 -q " ... "'


EXECUTE xp_cmdshell 'sqlcmd -S COMPUTER_A\INSTANCE_02 -q " ... "'

To do the dirty work.

There is to be expected from this xp_cmdshell/sqlcmd lever only text output (or other hbn considering the ssmse options available) but very tough operations where tables are mirrored or complex operations during maintenance or upgrade are created or refreshed should perform as expected.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01-2016 | 2.8.180212.1 | Last Updated 26 Oct 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100