declare @hr int, @pobj int, @dbobj int
declare @source varchar(30), @desc varchar (200)
/* create a new SQLOLE object */
-- For SQL Server 6.0/6.5, change SQLDMO.SQLServer to SQLOLE.SQLServer
exec @hr = sp_OACreate "SQLDMO.SQLServer", @pobj out
if @hr <> 0
goto Error_Handler
/* open a connection to the local database */
exec @hr = sp_OAMethod @pobj, 'Connect("(local)", "testuser", "testpwd")'
if @hr <> 0
goto Error_Handler
exec @hr = sp_OAMethod @pobj, 'Databases("pubs")', @dbobj OUT
if @hr <> 0
goto Error_Handler
-- Set maximum characters per column to >255 to see more of the output.
exec @hr = sp_OAMethod @dbObj, 'EnumUsers.GetRangeString'
if @hr <> 0
goto Error_Handler
exec @hr = sp_OAMethod @dbObj, 'EnumUsers.Columns'
if @hr <> 0
goto Error_Handler
goto Done
Error_Handler:
Print '*** ERROR ***'
exec sp_OAGetError_HandlerorInfo null, @source OUT, @desc OUT
select hr = convert (binary(4), @hr), source = @source, description = @desc
goto Done
Done:
exec sp_OADestroy @pobj
This page was last updated on May 01, 2006 04:28 PM.