The ExecuteWithResultsAndMessages method executes a Transact-SQL command batch returning batch result sets in a QueryResults object and capturing messages raised as part of command batch execution.
Database Object | RemoteServer Object |
LinkedServer Object | SQLServer Object |
object.ExecuteWithResultsAndMessages( Command , Messages , [ Length ] )
as QueryResults
Part | Description |
---|---|
object | Expression that evaluates to an object in the Applies To list. |
Command | String specifying a Transact-SQL or provider-specific command batch. |
Messages | String used to return message output. |
Length | Optional. A long integer indicating the statement batch length. |
A QueryResults object containing command batch results. The method fills the string specified by the Messages argument with message returns, if any are generated by batch execution.
For Microsoft® SQL Server™, error severity indicates the degree of an error condition. Some errors are severe enough to terminate statement execution prematurely. Any error with a severity of 10 or higher is returned to the SQL-DMO application through normal error handling.
More benign errors indicate that statement execution succeeded, but that success was conditional. Success-with-information errors, called messages, are SQL Server errors with a severity of less than 10. Some Transact-SQL statements, such as the PRINT statement, do not generate result sets, using messages for their return value.
The ExecuteWithResultsAndMessages method implements command batch execution for a SQL-DMO application, allowing the application to capture success-with-information errors or other information transmitted as messages.
Note When using the ExecuteWithResultsAndMessages method with the LinkedServer object, command batch syntax is provider-specified. Some OLE DB providers may support message returns as defined for SQL Server. For more information, see your OLE DB provider documentation.
HRESULT ExecuteWithResultsAndMessages(
SQLDMO_LPCSTR Command,
LPSQLDMOQUERYRESULTS* ppResults,
SQLDMO_LPBSTR Messages,
long lLength CPPDEFAULT(= 0));
Note SQL-DMO strings are always returned as OLE BSTR objects. A C/C++ application obtains a reference to the string. The application must release the reference by using SysFreeString.