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.
| Author |
Topic |
|
marat
Yak Posting Veteran
85 Posts |
Posted - 2008-01-24 : 18:36:21
|
| Hi,Disk Space Left SP I am using is working fine in SQL2K, but when I am running the same SP in SQL2K5(I replaced xp_sendmail with msdb.dbo.sp_send_dbmail) I get an error initializing COM.If I am running sp_send_dbmail separately it works ok, but if it is running in a batch it fails.In my SP I am also using EXEC @hr=sp_OACreate 'Scripting.FileSystemObject',@fso OUT It looks like FileSystemObject and sp_send_dbmail are conflicting.If I comment out any of them ERROR disappears.Any ideas what could cause an error.Thanksmarat |
|
|
marat
Yak Posting Veteran
85 Posts |
Posted - 2008-01-29 : 06:35:37
|
| Still can't get answer.Attaching not working script(In SQL2K5).SET NOCOUNT ONDECLARE@Percentagefree int,@error2 varchar(8000)set @Percentagefree = 50DECLARE @hr intDECLARE @fso intDECLARE @drive char(1)DECLARE @odrive intDECLARE @TotalSize varchar(20)DECLARE @MB bigint SET @MB = 1048576DECLARE @COUNT intDECLARE @Maxcount intDECLARE @error varchar(700)DECLARE @errordrive char(1)DECLARE @errortotalspace varchar(20)DECLARE @errorfreespace varchar(20)DECLARE @free intDECLARE @date varchar(100)declare @query varchar(1300)set @date = convert(varchar(100), getdate(),109)set @error2=''select @query= 'master.dbo.xp_fixeddrives'CREATE TABLE #drives (id int identity(1,1),ServerName varchar(15),drive char(1) PRIMARY KEY,FreeSpace int NULL,TotalSize int NULL,FreespaceTimestamp DATETIME NULL)INSERT #drives(drive,FreeSpace)EXEC @queryEXEC @hr=sp_OACreate 'Scripting.FileSystemObject',@fso OUTIF @hr <> 0 EXEC sp_OAGetErrorInfo @fsoDECLARE dcur CURSOR LOCAL FAST_FORWARDFOR SELECT drive from #drivesORDER by driveOPEN dcurFETCH NEXT FROM dcur INTO @driveWHILE @@FETCH_STATUS=0BEGINEXEC @hr = sp_OAMethod @fso,'GetDrive', @odrive OUT, @driveIF @hr <> 0 EXEC sp_OAGetErrorInfo @fsoEXEC @hr = sp_OAGetProperty @odrive,'TotalSize', @TotalSize OUTIF @hr <> 0 EXEC sp_OAGetErrorInfo @odriveUPDATE #drivesSET TotalSize=@TotalSize/@MB, ServerName = replace( @query , 'master.dbo.xp_fixeddrives',''), FreespaceTimestamp = (GETDATE())WHERE drive=@driveFETCH NEXT FROM dcur INTO @driveENDCLOSE dcurDEALLOCATE dcurEXEC @hr=sp_OADestroy @fsoIF @hr <> 0 begin EXEC sp_OAGetErrorInfo @fso; print 'error'; endprint 'no error'set @maxcount =(select max(id) from #drives)set @count=1while @count <=@maxcountbeginselect @errortotalspace =convert(varchar(20),Totalsize), @errorfreespace =freespace, @free=CAST((FreeSpace/(TotalSize*1.0))*100.0 as int),@errordrive=Drive from #drives where id = @countif @free<@percentagefreebeginset @error = 'Server = '+@@servername+': Drive=' + @errordrive+': Percentage free=' +convert(varchar(2),@free)+'% TotalSpace ='+ @errortotalspace +'MB : FreeSpace ='+ @errorfreespace +'MB :Date =' +@date set @error2=@error2+@error+char(13)endelsebeginset @error = 'Server = '+@@servername+': Drive=' + @errordrive+': Percentage free=' +convert(varchar(2),@free)+'% TotalSpace ='+ @errortotalspace +'MB : FreeSpace ='+ @errorfreespace +'MB :Date =' +@date endset @count=@count+1end--select * from #drivesDROP TABLE #drivesset @date = convert(varchar(100), getdate(),109)--EXEC msdb.dbo.sp_send_dbmail @profile_name = 'SQLDBMailProfile', @recipients = 'marat@primus.com', @body = 'The stored procedure finished successfully.', @query = 'SELECT 5',-- @execute_query_database = 'msdb',-- @attach_query_result_as_file = 1, @append_query_error = 1, @subject = 'Automated Success Message'-- @body_format = 'HTML' Any clues?Thanks |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
marat
Yak Posting Veteran
85 Posts |
Posted - 2008-01-29 : 07:05:59
|
| Thanks Peso. Tara's method is nice.But I really want to know what is wrong with the script I am using?Why sp_send_dbmail fails when using @query parameter?marat |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-01-29 : 07:07:50
|
Well, at least now we know that it is the mailing part that produces the error... E 12°55'05.25"N 56°04'39.16" |
 |
|
|
marat
Yak Posting Veteran
85 Posts |
Posted - 2008-01-29 : 21:02:05
|
| Hi Peso,I used Tara's DLL; it works fine with sp_send_dbmail.Special credits to Tara.Thank youmarat |
 |
|
|
|
|
|
|
|