Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


TSQL about more Servers


TSQL about more Servers

Author
Message
mick miller
mick miller
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
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
mick miller
mick miller
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 Visits: 44
This command doesn't run too:

EXEC sp_MSforeachdb @command1 = 'select * from srvdentw.?.sys.database_files'
RBarryYoung
RBarryYoung
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10060 Visits: 9517
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."
Florian Reischl
Florian Reischl
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2121 Visits: 3934
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
mick miller
mick miller
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
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
mick miller
mick miller
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
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
RBarryYoung
RBarryYoung
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10060 Visits: 9517
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."
Florian Reischl
Florian Reischl
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2121 Visits: 3934
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
ALZDBA
ALZDBA
SSCertifiable
SSCertifiable (7.9K reputation)SSCertifiable (7.9K reputation)SSCertifiable (7.9K reputation)SSCertifiable (7.9K reputation)SSCertifiable (7.9K reputation)SSCertifiable (7.9K reputation)SSCertifiable (7.9K reputation)SSCertifiable (7.9K reputation)

Group: General Forum Members
Points: 7949 Visits: 8845
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


Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere w00t

- 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 :-D


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me Alien but most of the time this is me Hehe
RBarryYoung
RBarryYoung
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10060 Visits: 9517
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."
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search