Run Com based process outside SQL server (sp_OACreate 'CDO.Message')

  • I have run into an issue in my SQL server (SQL 2K5 64Bit). After a while, the memory just tanks and the system becomes unusable. This is usually without warning until it is to late. I opened a case with Microsoft and sent them all the information they asked for and they came bakc with a few suggestions. One of them may possibly to do with sp_OACreate...

    I do see xpSLS and SQLDMO as well. Try if we can move SQLDMO out of process too. most likely coming in because of sp_oacreate.

    I read an artcle on this and tried to run this process outside the SQL space by specifying the parameter rather than using the default value. When I do so, the whole process fails. In short, EXEC @hr = sp_OACreate 'CDO.Message', @iMsg OUT

    works fine. however EXEC @hr = sp_OACreate 'CDO.Message', @iMsg OUT,4 does not.

    Help?

    Kindest Regards,
    David

    ** Obstacles are those frightening things that appear when we take our eyes off the goal. **

  • CREATE PROCEDURE [dbo].[sp_send_cdosysmail]

    @From varchar(100) ,

    @To varchar(100) ,

    @Subject varchar(100)=" ",

    @Body varchar(4000) =" ",

    @attachment nvarchar(100)= " ",

    @bodytype varchar(10)=" "

    /*********************************************************************

    This stored procedure takes the parameters and sends an e-mail.

    All the mail configurations are hard-coded in the stored procedure.

    Comments are added to the stored procedure where necessary.

    References to the CDOSYS objects are at the following MSDN Web site:

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdosys/html/_cdosys_messaging.asp

    ***********************************************************************/

    AS

    Declare @iMsg int

    Declare @hr int

    Declare @source varchar(255)

    Declare @description varchar(500)

    Declare @output varchar(1000)

    declare @Comment Varchar(1000)

    --************* Create the CDO.Message Object ************************

    EXEC @hr = sp_OACreate 'CDO.Message', @iMsg OUT

    --***************Configuring the Message Object ******************

    -- This is to configure a remote SMTP server.

    -- http://msdn.microsoft.com/library/default.asp?url=/library/en-

    us/cdosys/html/_cdosys_schema_configuration_sendusing.asp

    EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields

    ("http://schemas.microsoft.com/cdo/configuration/sendusing").Value','2'

    -- This is to configure the Server Name or IP address.

    -- Replace MailServerName by the name or IP of your SMTP Server.

    EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields

    ("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value', ** smtp server name***

    -- Save the configurations to the message object.

    EXEC @hr = sp_OAMethod @iMsg, 'Configuration.Fields.Update', null

    -- Set the e-mail parameters.

    EXEC @hr = sp_OASetProperty @iMsg, 'To', @To

    EXEC @hr = sp_OASetProperty @iMsg, 'From', @From

    EXEC @hr = sp_OASetProperty @iMsg, 'Subject', @Subject

    -- If you are using HTML e-mail, use 'HTMLBody' instead of 'TextBody'.

    Select @bodytype=

    CASE @bodytype

    when ' ' then 'TextBody'

    else @bodytype

    end

    print @attachment

    EXEC @hr = sp_OASetProperty @iMsg, @bodytype, @Body

    if @attachment is not null

    begin

    EXEC @hr = sp_OAMethod @iMsg, 'AddAttachment',@Comment out, @attachment

    end

    --EXEC @hr = sp_OASetProperty @iMsg, 'Attachment',

    --EXEC @hr = sp_OAMethod @iMsg, 'AddAttachment', 'http://someuri/picture.gif'

    --EXEC @hr = sp_OAMethod @iMsg, 'AddAttachment', 'C:\file.txt'

    EXEC @hr = sp_OAMethod @iMsg, 'Send', NULL

    -- Sample error handling.

    IF @hr <>0

    select @hr

    BEGIN

    EXEC @hr = sp_OAGetErrorInfo NULL, @source OUT, @description OUT

    IF @hr = 0

    BEGIN

    SELECT @output = ' Source: ' + @source

    PRINT @output

    SELECT @output = ' Description: ' + @description

    PRINT @output

    END

    ELSE

    BEGIN

    PRINT ' sp_OAGetErrorInfo failed.'

    RETURN

    END

    END

    -- Do some error handling after each step if you have to.

    -- Clean up the objects created.

    EXEC @hr = sp_OADestroy @iMsg

    Kindest Regards,
    David

    ** Obstacles are those frightening things that appear when we take our eyes off the goal. **

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

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