The sp_OACreat

  • Executing the code below when Query Analyser points to Master Database gives the following error message:

    "Error Occurred Calling Object: ODSOLE Extended Procedure sp_OADestroy usage: ObjPointerToBeDestroyed int IN"]

    Any idea what is wrong with this code:

    DECLARE @Object int

    DECLARE @Hresult int

    DECLARE @Word varchar(255)

    DECLARE @SpelledCorrectly bit

    DECLARE @ErrorSource varchar (255)

    DECLARE @ErrorDesc varchar (255)

    SET @Word = 'philanthropist'

    --SET @Word = 'filanthropist'

    --Create the object

    EXEC @Hresult = sp_OACreate 'Word.Application', @Object OUT

    --Call the object's property and return the value

    EXEC @Hresult = sp_OAMethod @Object, 'CheckSpelling', @SpelledCorrectly OUT, @Word

    --Destroy the object

    EXEC @Hresult = sp_OADestroy @Object

    IF @Hresult <> 0

    BEGIN

    EXEC sp_OAGetErrorInfo @Object, @ErrorSource OUT, @ErrorDesc OUT

    PRINT 'Error Occurred Calling Object: ' + @ErrorSource + ' ' + @ErrorDesc

    RETURN

    END

    IF @SpelledCorrectly = 1

    BEGIN

    PRINT 'The word ' + @Word + ' was spelled correctly.'

    END

    ELSE BEGIN

    PRINT 'The word ' + @Word + ' was spelled incorrectly.'

    END

  • Runs fine on mine with Master DB.


    Regards,

    goodguy

    Experience is a bad teacher whose exams precede its lessons

  • I have not been able to get any example of sp_oacreate to run successfully yet. I tried on 2008R2X64 Developer edition no luck. I upgraded to 2014SP2X64 Developer edition no luck. I can only surmise it is some kind of security either in sql server or on the object trying to be created. In this case a word object.
    I have tried DMO and SMO and have not been able to create an object with those either. I am very very sad. Any tips appreciated.

  • Needy Info-318558 - Thursday, January 12, 2017 2:30 PM

    I have not been able to get any example of sp_oacreate to run successfully yet. I tried on 2008R2X64 Developer edition no luck. I upgraded to 2014SP2X64 Developer edition no luck. I can only surmise it is some kind of security either in sql server or on the object trying to be created. In this case a word object.
    I have tried DMO and SMO and have not been able to create an object with those either. I am very very sad. Any tips appreciated.

    SQLCLR or Powershell would likely be better options for this.
    I think the OLE Automation procedures started breaking in 64 bit SQL 2005 and have been inconsistent in whether they work on not on subsequent versions. In 2005 it was a 64 bit  calling a 32 bit COM dll which was the issue. I haven't followed it too much since then since those are likely to go away one of these days. But I've seen the issues and nothing is really consistent with when the errors happen. If you read some posts, there doesn't seem to be much rhyme or reason as to when it breaks in terms of versions, architecture.

    Sue

  • Sue_H - Thursday, January 12, 2017 4:49 PM

    Needy Info-318558 - Thursday, January 12, 2017 2:30 PM

    I have not been able to get any example of sp_oacreate to run successfully yet. I tried on 2008R2X64 Developer edition no luck. I upgraded to 2014SP2X64 Developer edition no luck. I can only surmise it is some kind of security either in sql server or on the object trying to be created. In this case a word object.
    I have tried DMO and SMO and have not been able to create an object with those either. I am very very sad. Any tips appreciated.

    SQLCLR or Powershell would likely be better options for this.
    I think the OLE Automation procedures started breaking in 64 bit SQL 2005 and have been inconsistent in whether they work on not on subsequent versions. In 2005 it was a 64 bit  calling a 32 bit COM dll which was the issue. I haven't followed it too much since then since those are likely to go away one of these days. But I've seen the issues and nothing is really consistent with when the errors happen. If you read some posts, there doesn't seem to be much rhyme or reason as to when it breaks in terms of versions, architecture.

    Sue

    Thank you for the quick reply. The 64 bit calling the 32 bit makes a great deal of sense and I did not think of that. I don't have a particular use right at this moment for the OLE. Here is an interesting result of my tests. ADODB.RecordSet and Scripting.FileSystemObject objects get created without error. Word.Application and DTS.Package throw errors. I agree with you, I think I will stay away due to the inconsistent results.

Viewing 5 posts - 1 through 4 (of 4 total)

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