Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

TSQL about more Servers Expand / Collapse
Author
Message
Posted Sunday, June 14, 2009 2:12 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, February 12, 2010 12:48 AM
Points: 15, Visits: 44
Hello

I have an SQL-Server 2008 management server from witch I start a TSQL like that:
EXEC sp_MSforeachdb @command1 = 'select * from ?.sys.database_files'

How I do this for more Servers?

I tried with this command, but it doesn't run:
USE Server1.master
EXEC sp_MSforeachdb @command1 = 'select * from ?.sys.database_files'

I configured a linked server to Server1.

Thanks a lot
miller
Post #734557
Posted Sunday, June 14, 2009 2:22 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, February 12, 2010 12:48 AM
Points: 15, Visits: 44

This command doesn't run too:

EXEC sp_MSforeachdb @command1 = 'select * from srvdentw.?.sys.database_files'

Post #734560
Posted Sunday, June 14, 2009 2:24 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Friday, March 28, 2014 2:25 PM
Points: 9,902, Visits: 9,479
If you tell us what "doesn't run" means we should be able to help you better.

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Post #734561
Posted Sunday, June 14, 2009 4:30 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Sunday, November 04, 2012 12:23 PM
Points: 2,087, Visits: 3,932
mick miller (6/14/2009)
USE Server1.master


USE statement only works for local databases. Try callin' like this:
EXECUTE Server1.master.sys.sp_msforeachdb 'PRINT ''?'''

This requires RPC to be enabled.

Another option would be a hack by using OPENQUERY.

Flo



The more I learn, the more I know what I do not know
Blog: Things about Software Architecture, .NET development and T-SQL

How to Post Data/Code to get the best Help How to Post Performance Problems
Post #734573
Posted Sunday, June 14, 2009 9:59 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, February 12, 2010 12:48 AM
Points: 15, Visits: 44
Msg 7314, Level 16, State 1, Line 1
The OLE DB provider "SQLNCLI10" for linked server "srvdentw" does not contain the table ""model"."sys"."database_files"". The table either does not exist or the current user does not have permissions on that table.

the linked server user is the same user as the service is started on remote sql-server

thanks miller

Post #734621
Posted Sunday, June 14, 2009 10:02 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, February 12, 2010 12:48 AM
Points: 15, Visits: 44
Hello

EXECUTE srvdentw.master.sys.sp_msforeachdb 'PRINT ''?'''

Msg 7411, Level 16, State 1, Line 1
Server 'srvdentw' is not configured for RPC.

Thanks miller
Post #734622
Posted Sunday, June 14, 2009 11:53 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Friday, March 28, 2014 2:25 PM
Points: 9,902, Visits: 9,479
mick miller (6/14/2009)
Hello

EXECUTE srvdentw.master.sys.sp_msforeachdb 'PRINT ''?'''

Msg 7411, Level 16, State 1, Line 1
Server 'srvdentw' is not configured for RPC.

Thanks miller


Either turn on RPC, or try it like this:
EXEC ('EXECUTE master.sys.sp_msforeachdb ''PRINT ''''?'''''''')  AT srvdentw



-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Post #734650
Posted Sunday, June 14, 2009 12:32 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Sunday, November 04, 2012 12:23 PM
Points: 2,087, Visits: 3,932
Wow! Never saw this syntax. Thanks Barry!

@mick miller: I think EXECUTE AT should be the most simple solution.

Flo



The more I learn, the more I know what I do not know
Blog: Things about Software Architecture, .NET development and T-SQL

How to Post Data/Code to get the best Help How to Post Performance Problems
Post #734666
Posted Sunday, June 14, 2009 12:43 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Friday, April 18, 2014 6:27 AM
Points: 6,997, Visits: 8,411
I always try to avoid linked servers !

With sql2008 SSMS you can connect to a server group and execute a centrain sql script at onece on the whole group !!
This is a very cool feature ! (Check books online)


Off course you could also SQLCMD to connect to your # servers and collect the data you want.



Johan


Don't drive faster than your guardian angel can fly ...
but keeping both feet on the ground won't get you anywhere

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


"press F1 for solution", "press shift+F1 for urgent solution"


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me but most of the time this is me
Post #734671
Posted Sunday, June 14, 2009 1:37 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Friday, March 28, 2014 2:25 PM
Points: 9,902, Visits: 9,479
Florian Reischl (6/14/2009)
Wow! Never saw this syntax. Thanks Barry!

Thanks, Flo. It's in BOL, but I think that I learned it from Erland's blog.


-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Post #734690
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse