T-SQL을 이용해 COM Object를 호출하는 방법

 

자세한 내용은 Books Online을 참조하라니 --;;

혹시 쓸 일이 있을거 같아 본김에 퍼놓았습니다.

더 좋은 ref가 있으면 알려주심 ㄳ

 

출처 : http://www.sqlteam.com/item.asp?ItemID=322

 

Calling COM Objects From T-SQL
sqlguru on 9/13/2000 in Stored Procs
Dan (and Nathan, and a few others) writes: "I've heard/read that you can call a COM Object from within a stored proc. Could you explain how this is done?"

Yup. This is fairly straightforward; check it out.

The functions mentioned here are all well documented in SQL Server Books Online, so I'm not going to go into a lot of detail. If you have further questions, you know where to send them :)

Calling a COM object from T-SQL is pretty easy. First, you call sp_OACreate to create an instance of the object. This stored proc returns an integer value (a handle) that you'll need later.

Next, you call sp_OAMethod to invoke a method of the object. sp_OAGetProperty will retrieve the value of a property from the object; conversely, sp_OASetProperty will set the value of one of the object's properties.

While you're calling these stored procs to manipulate the object, you use sp_OAGetErrorInfo after each call to see if the object threw an error. Error handling for COM object calls is mostly a manual process, so be prepared to do a lot of typing :)

Once you're done using the object, you call sp_OADestroy to free the object. Objects that aren't explicitly freed are automatically freed by SQL Server at the end of the query batch.

Since COM and SQL Server data types don't match up exactly, I suggest you check out the topic titled "Data Type Conversions Using OLE Automation Stored Procedures" in Books Online.

Books Online also has a topic titled "OLE Automation Sample Script" that has a nice example of calling all of these procedures.

-SQLGuru

'programming > MSSQL' 카테고리의 다른 글

Reusing Identities  (0) 2003.12.09
TSQL 이야기 - UNION  (0) 2003.11.28
TSQL 이야기...  (0) 2003.11.28

+ Recent posts