January 19, 2007 at 2:36 pm
Hello everyone,
I'm trying to automate my monitoring of SQL Server fixed drives using XP_FixedDrives. The procedure below works for the EXEC part but produces an error when Insert .. Exec() is used.
Please help.
--Preparations
CREATE TABLE [MonitoredServerNames] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[ServerName] [nvarchar] (130) )
GO
-- Insert all monitored servers
Insert into MonitoredServerNames(ServerName)
Values ('[CCNT_ASAP]')
Insert into MonitoredServerNames(ServerName)
Values ('[COMMERCEDBSQL1]')
Insert into MonitoredServerNames(ServerName)
Values ('[CRMCLUSTERSQL1]')
Insert into MonitoredServerNames(ServerName)
Values ('[CRMCLUSTERSQL2\NODE2]')
Insert into MonitoredServerNames(ServerName)
Values ('[CSESQL2]')
Insert into MonitoredServerNames(ServerName)
Values ('[HQCORPSQL\NODE4]')
Insert into MonitoredServerNames(ServerName)
Values ('[HQJOBS1]')
Insert into MonitoredServerNames(ServerName)
Values ('[HQSEARCH3]')
Insert into MonitoredServerNames(ServerName)
Values ('[ISB]')
GO
-- Procedure begins here
Create Table #Drives
(drive char(1), FreeMB int)
declare @ServerName varchar(100)
declare @SQL varchar(200)
declare ServerNames cursor for
select ServerName from MonitoredServerNames (nolock)
Open ServerNames
Fetch next from ServerNames into @ServerName
While @@Fetch_Status = 0
Begin
Set @SQL = 'EXEC ' + @ServerName + '.master..xp_fixeddrives'
Insert #Drives --Comment this line and it works!
exec (@SQL)
/*
Select 'Server' = @ServerName, Drive, FreeMB,
Status = case when FreeMB < 2000
then 'Critical'
else 'OK' end
from #Drives
truncate table #Drives
*/
Fetch next from ServerNames into @ServerName
End
Close ServerNames
Deallocate ServerNames
Drop table #Drives
Server: Msg 7391, Level 16, State 1, Line 1
The operation could not be performed because the OLE DB provider 'SQLOLEDB' was unable to begin a distributed transaction.
[OLE/DB provider returned message: New transaction cannot enlist in the specified transaction coordinator. ]
OLE DB error trace [OLE/DB Provider 'SQLOLEDB' ITransactionJoin::JoinTransaction returned 0x8004d00a].
January 19, 2007 at 11:01 pm
The column names in the #Drives table must be the same as those returned by the xp. You have FreeMB as one of the column names... you need to either change it to [MB Free]...
OR
You need to name the insert list (probably the more logical way to do it).... like this....
INSERT INTO #Drives (Drive,FreeMB)
EXEC (@SQL)
Also, you probably have SA privs if you are writting such routines... if so, give this baby a whirl... capture the output from THAT and you'll automatically pickup new servers on the network... some you might have even missed...
EXEC Master.dbo.xp_CmdShell 'OSQL -L'
--Jeff Moden
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply