sp_OAMethod example

  • Hi,

    Found the following example in BOL,

    declare @property varchar(255)

    declare @hr int

    declare @object int

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

    if @hr <> 0

    begin

    exec sp_OAGetErrorInfo @object

    return

    end

    print @property

    When I try to run this example (as a user with sysadmin role), I am getting this error message,

    Server: Msg 10019, Level 16, State 1, Line 0

    sp_OACreate has not yet been called successfully for this command batch.

    Server: Msg 10019, Level 16, State 1, Line 0

    sp_OACreate has not yet been called successfully for this command batch.

  • And did you look up sp_OACreate in BOL?

    as far as I recall OACreate must be called to instantiate the object, just as any constructor process is required in OO.  Only then can you call a method on it.  The @Object variable in that example is the reference object id that will be created in OACreate.

    In any use of objects you must create and destroy them around any use of their methods.

     

  • We just had the article here on 10/31/2005 on the topic with good examples:

    http://qa.sqlservercentral.com/columnists/dasanka/callingcomfromtsql.asp

    Calling COM From T-SQL

    by Dinesh Asanka

    I added it to my virtual briefcase

    Regards,Yelena Varsha

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

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