共用方式為


ExecuteWithResultsAndMessages Method

未來的 Microsoft SQL Server 發行版本將不再提供此功能。請避免在新的開發工作中使用此功能,並計劃修改目前使用此功能的應用程式。

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.

語法

object
.ExecuteWithResultsAndMessages(
Command 
,
Length
,
Messages
)
as
QueryResults

Parts

  • object
    Expression that evaluates to an object in the Applies To list.
  • Command
    String that specifies a Transact-SQL or provider-specific command batch.
  • Length
    Long integer that indicates the statement batch length.
  • Messages
    String used to return message output.

Prototype (C/C++)

HRESULT ExecuteWithResultsAndMessages(
SQLDMO_LPCSTR Command,
LPSQLDMOQUERYRESULTS* ppResults,
SQLDMO_LPBSTR Messages,
long lLength);
ms135150.note(zh-tw,SQL.90).gif附註:
SQL Distributed Management Objects (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 using SysFreeString.

Returns

A QueryResults object that contains command batch results. The method fills the string specified by the Messages argument with message returns, if any are generated by batch execution.

備註

The ExecuteWithResultsAndMessages2 method extends the functionality of the ExecuteWithResultsAndMessages method.

Visual Basic applications should call ExecuteWithResultsAndMessages2 instead of ExecuteWithResultsAndMessages. ExecuteWithResultsAndMessages2 is not available to C++ applications, which should call ExecuteWithResultsAndMessages.

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.

Minor errors, SQL Server errors with a severity of less than 10, indicate that statement execution succeeded, but that success was conditional. These are called Success-with-information errors. Some Transact-SQL statements, such as the PRINT statement, do not generate result sets, using messages for their return value.

The ExecuteWithResultsAndMessages2 method implements command batch execution for a SQL Distributed Management Objects (SQL-DMO) application, allowing the application to capture success-with-information errors or other information transmitted as messages.

ms135150.note(zh-tw,SQL.90).gif附註:
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 the OLE DB provider documentation.

Applies To:

Database Object

RemoteServer Object

LinkedServer Object

SQLServer Object

請參閱

參考

ExecuteWithResultsAndMessages2 Method

說明及資訊

取得 SQL Server 2005 協助