SQL Query SQLDMO
===

Following is my SQL Query which work fine on  SQL server 2005 ,but on SQL Server 2008 its throws the Error sp_Security error: Unable to create SQLDMO Server object

 Thanks.

SQL Query

> DECLARE @object int

>DECLARE @hr int

>DECLARE @hack smallint

>DECLARE @return varchar(255)

>DECLARE @Results nvarchar(255)

>DECLARE @server sysname

>DECLARE @login sysname

>DECLARE @tsql varchar(1500)

>set @server = 'YOGESH\SQLEXPRESS'

>EXEC @hr = sp_OACreate 'SQLDMO.SQLServer', @object OUT

>IF @hr <> 0

>BEGIN

>   RAISERROR('sp_Security error: Unable to create SQLDMO Server object', 0, 1)

>RETURN

>END

>EXEC @hr = sp_OASetProperty @object,'LoginSecure', 'False'

>IF @hr <> 0

>BEGIN

> RAISERROR('sp_Security error: Unable to set LoginSecure', 0, 1)

> GOTO ExitProc

> END
   
>Print ' Security Audit for Server : ' + @server

>set @tsql = 'DECLARE login_cursor CURSOR FOR SELECT loginname FROM master.dbo.syslogins order by loginname' 

>exec (@tsql)

>OPEN login_cursor

>FETCH NEXT FROM login_cursor
>INTO @login

>WHILE @@FETCH_STATUS = 0

>BEGIN

>set @hack = 0

>set @Results = 'Connect("' + @server +'","'+@login+'","'+@login+'")'

>EXEC @hr = sp_OAMethod @object, @Results

>IF @hr = 0

>begin

>print 'login : ' + @login + ' security problem with password ' + @login

>EXEC @hr = sp_OAMethod @object, 'Disconnect'

>set @hack = 1

>end

>IF (@hack = 0)

>begin

>set @Results = 'Connect("' + @server +'","'+@login+'","'+'")'

>EXEC @hr = sp_OAMethod @object, @Results

>IF @hr = 0

>begin

>print 'login : ' + @login + ' security problem with password NULL'

>EXEC @hr = sp_OAMethod @object, 'Disconnect'

>set @hack = 1

>end

>end
