• subscribe
December 30, 1999 12:00 AM

Learning About OLE Automation Stored Procedures

SQL Server Pro
InstantDoc ID #7910

The system stored procedures in SQL Server often yield interesting and unexpected surprises. You can find a system stored procedure to handle nearly any task you need to do. This week, I discovered the OLE automation (sp_OA) stored procedures, which let you instantiate and work with COM objects from within Transact SQL (T-SQL). You can use these procedures to create a COM object in T-SQL and use that object’s methods and properties. For example, you can use the File System object to open and process files, and you can read and write to files by using the File System object directly within T-SQL.

You can call the OLE automation procedure sp_OACreate and pass it a program ID or class ID and variable, and the procedure will instantiate the object for you. The variable will serve as a reference to the object for all further interactions that involve the other sp_OA stored procedures. After you have used sp_OACreate, you can use sp_OASetProperty and sp_OAGetProperty to set and retrieve property values. You use sp_OAMethod to execute an object’s methods.

When your script is finished using an object, you can use sp_OADestroy to destroy the object. If you don’t call sp_OADestroy, the object will be destroyed automatically when the T-SQL batch completes execution.

You can call sp_OAStop to close the OLE Automation services. After you stop these services, they will automatically restart the next time you call one of the sp_OA stored procedures.

You don't want to overuse the OLE automation stored procedures because they might cause performance problems. Also, the procedures might cause stability problems because running objects in the SQL Server process can cause SQL Server to crash. These caveats aside, sp_OA support lets you do things you can’t do another way.



ARTICLE TOOLS

Comments
  • Taylor
    2 years ago
    Aug 07, 2010

    yea, this article is weak. I realize it is 2010 but believe it or not some companies still have sql2000 installs that don't work. I paid 5.95 to find out nothing. Thanks

  • Anonymous User
    8 years ago
    Nov 03, 2004

    worthless article

  • Paul Schlieper
    10 years ago
    Dec 19, 2002

    Unless I missed the link to page 2, this article merely tells you what is possible. There is no value-added, this is already free, publicly available information.

  • Bruno Smessaert
    11 years ago
    Nov 05, 2001

    I can't found the sp_OA.. in all store procedure on the SQL server 7. Then when i want to execute a store procedure with sp_OA that don't work. Where is possible to find the group of sp_OA procedure to execute my future procedure.
    Thank you.

You must log on before posting a comment.

Are you a new visitor? Register Here