Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 Script Across multiple connections

Author  Topic 

Big_tim
Starting Member

22 Posts

Posted - 2010-03-18 : 12:49:27
Hi again,
Now I've got some daily check scripts sorted which I'm running manually on (initially) 3 different servers I'd like to do a bit of automation.

What I'm doing at the moment is changing the connection manually each time and running this:

--Free space by drive:

EXEC master..xp_fixeddrives


--Last backup date.

SELECT
B.name as Database_Name,
ISNULL(STR(ABS(DATEDIFF(day, GetDate(), MAX(Backup_finish_date)))), 'NEVER') as DaysSinceLastBackup,
ISNULL(Convert(char(10), MAX(backup_finish_date), 101), 'NEVER') as LastBackupDate

FROM
master.dbo.sysdatabases B
LEFT OUTER JOIN msdb.dbo.backupset A
ON A.database_name = B.name AND A.type = 'D'


Which obviously gives free space per drive and last backup date.

How do I go about scripting this so it connects to the 3 different servers one at a time (eg Server1, Server2 & Server3) and updates the tables in my DB I've created on my local machine? (I'll be creating a report in reporting services with this data)

Hope that makes sence!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-18 : 13:48:05
I would create a .NET CLR stored procedure on your central server that goes out to the remote servers and collects the information.

Although this one doesn't collect the data that you need, the concept is the same: http://weblogs.sqlteam.com/tarad/archive/2008/12/16/How-to-track-database-growth-across-multiple-SQL-Server-instances.aspx

It was also featured in the online version of SQL Server Magazine, since this concept can be used to collect all sorts of things: http://weblogs.sqlteam.com/tarad/archive/2009/10/08/SQL-Server-Magazine-web-article-about-a-tool-I-wrote.aspx

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -