Calls a method of an OLE object.
sp_OAMethod objecttoken, methodname, [returnvalue OUTPUT
[, [@parametername =] parameter [OUTPUT]...]]
where
To obtain the return value of an output parameter, parameter must be a local variable of the appropriate datatype, and OUTPUT must be specified. If a constant parameter is specified, or if OUTPUT is not specified, any return value from an output parameter is ignored.
If specified, parametername must be the name of the Visual Basic named parameter. Note that @parametername is not a Transact-SQL local variable. The at (@) is removed, and parametername is passed to the OLE object as the parameter name. All named parameters must be specified after all positional parameters are specified.
If the method returns a single value, either:
Or
If the method return value is an OLE object, you must specify a local variable of datatype int for the returnvalue parameter. An object token will be stored in the local variable, and this object token can be used with other OLE Automation stored procedures.
If the method return value is an array with one or two dimensions, the array will be returned to the client as a results set as follows:
When the method return value is an array, if returnvalue is specified, it is set to NULL.
An error occurs under any of the following circumstances:
Note that sp_OAMethod can also be used to get a property value.
This procedure returns a 0 when successful or a non-zero HRESULT when an error occurs.
This example calls the Connect method of the previously created SQLServer object.
EXEC @hr = sp_OAMethod @object, 'Connect', NULL, 'my_server', 'my_login', 'my_password' IF @hr <> 0 BEGIN EXEC sp_displayoaerrorinfo @object, @hr RETURN END
This example gets the HostName property (of the previously created SQLServer object) and stores it in a local variable.
DECLARE @property varchar(255) EXEC @hr = sp_OAMethod @object, 'HostName', @property OUT IF @hr <> 0 BEGIN EXEC sp_displayoaerrorinfo @object, @hr RETURN END PRINT @property