ODSOLE Extended Procedure eror

  • I would like send mail through Stored procedure in SQL server But I am getting

    (0x80040154 , ODSOLE Extended Procedure , Class not registered) error when i execute the procedure

    code I am running:

    DECLARE @object int

    DECLARE @hr int

    DECLARE @property varchar(255)

    DECLARE @return varchar(255)

    DECLARE @src varchar(255), @desc varchar(255)

    -- Create a SQLServer object.

    SET NOCOUNT ON

    -- First, create the object.

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

    IF @hr <> 0

    begin

    -- Report the error.

    EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT

    SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc

    GOTO END_ROUTINE

    end

    ELSE

    -- An object is successfully created.

    BEGIN

    -- Set a property.

    EXEC @hr = sp_OASetProperty @object, 'HostName', 'Gizmo'

    IF @hr <> 0 GOTO CLEANUP

    -- Get a property using an output parameter.

    EXEC @hr = sp_OAGetProperty @object, 'HostName', @property OUT

    IF @hr <> 0

    GOTO CLEANUP

    ELSE

    PRINT @property

    -- Get a property using a result set.

    EXEC @hr = sp_OAGetProperty @object, 'HostName'

    IF @hr <> 0 GOTO CLEANUP

    -- Get a property by calling the method.

    EXEC @hr = sp_OAMethod @object, 'HostName', @property OUT

    IF @hr <> 0

    GOTO CLEANUP

    ELSE

    PRINT @property

    -- Call a method.

    -- SECURITY NOTE - When possible, use Windows Authentication.

    EXEC @hr = sp_OAMethod @object, 'Connect', NULL, 'my_server', 'my_login', 'my_password'

    IF @hr <> 0 GOTO CLEANUP

    -- Call a method that returns a value.

    EXEC @hr = sp_OAMethod @object, 'VerifyConnection', @return OUT

    IF @hr <> 0

    GOTO CLEANUP

    ELSE

    PRINT @return

    END

    CLEANUP:

    -- Check whether an error occurred.

    IF @hr <> 0

    BEGIN

    -- Report the error.

    EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT

    SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc

    END

    -- Destroy the object.

    BEGIN

    EXEC @hr = sp_OADestroy @object

    -- Check if an error occurred.

    IF @hr <> 0

    BEGIN

    -- Report the error.

    EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT

    SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc

    END

    END

    END_ROUTINE:

    RETURN

  • Don't use OLE objects to send mail in SQL 2005, use the Database Mail feature instead.

    However, if you're sending emails from an application, you'd better use a full-featured smtp client in your application. Database Mail was meant for alerting and reporting purposes and not to send messages to end users.

    -- Gianluca Sartori

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply