使用 QL Server 預設結果集Using SQL Server Default Result Sets

適用範圍:Applies to: 是SQL ServerSQL Server (所有支援的版本) yesSQL ServerSQL Server (all supported versions) 是Azure SQL DatabaseAzure SQL DatabaseYesAzure SQL DatabaseAzure SQL Database 是Azure SQL 受控執行個體Azure SQL Managed InstanceYesAzure SQL 受控執行個體Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics 是平行處理資料倉儲Parallel Data Warehouseyes平行處理資料倉儲Parallel Data Warehouse適用範圍:Applies to: 是SQL ServerSQL Server (所有支援的版本) yesSQL ServerSQL Server (all supported versions) 是Azure SQL DatabaseAzure SQL DatabaseYesAzure SQL DatabaseAzure SQL Database 是Azure SQL 受控執行個體Azure SQL Managed InstanceYesAzure SQL 受控執行個體Azure SQL Managed Instance 是Azure Synapse AnalyticsAzure Synapse AnalyticsyesAzure Synapse AnalyticsAzure Synapse Analytics 是平行處理資料倉儲Parallel Data Warehouseyes平行處理資料倉儲Parallel Data Warehouse

預設的 ODBC 資料指標屬性為:The default ODBC cursor attributes are:

SQLSetStmtAttr(hstmt, SQL_ATTR_CURSOR_TYPE, SQL_CURSOR_FORWARD_ONLY, SQL_IS_INTEGER);  
SQLSetStmtAttr(hstmt, SQL_ATTR_CONCURRENCY, SQL_CONCUR_READ_ONLY, SQL_IS_INTEGER);  
SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_ARRAY_SIZE, 1, SQL_IS_INTEGER);  

每當這些屬性設定為預設值時, SQL ServerSQL Server Native CLIENT ODBC 驅動程式就會使用 SQL ServerSQL Server 預設結果集。Whenever these attributes are set to their defaults, the SQL ServerSQL Server Native Client ODBC driver uses a SQL ServerSQL Server default result set. 預設結果集可用於任何受到 SQL ServerSQL Server 支援的 SQL 陳述式,而且是將整個結果集傳送到用戶端的最有效率的方法。Default result sets can be used for any SQL statement supported by SQL ServerSQL Server, and are the most efficient method of transferring an entire result set to the client.

SQL Server 2005 (9.x)SQL Server 2005 (9.x) 引進了 (MARS) 的多重作用中結果集支援;應用程式現在可以針對每個連接擁有一個以上的使用中預設結果集。introduced support for multiple active result sets (MARS); applications can now have more than one active default result set per connection. 預設不會啟用 MARS。MARS is not enabled by default.

SQL Server 2005 (9.x)SQL Server 2005 (9.x) 以前,預設結果集不能在相同連接上支援多個作用中陳述式。Before SQL Server 2005 (9.x)SQL Server 2005 (9.x), default result sets did not support multiple active statements on the same connection. 在連接上執行 SQL 陳述式以後,伺服器要等到結果集中的所有資料列都已經處理過後,才能在該連接上接受來自用戶端的命令 (取消其餘結果集的要求除外)。After an SQL statement is executed on a connection, the server does not accept commands (except a request to cancel the rest of the result set) from the client on that connection until all the rows in the result set have been processed. 若要取消部分處理之結果集的其餘部分,請呼叫 SQLCloseCursorSQLFreeStmt ,並將 fOption 參數設定為 SQL_CLOSE。To cancel the remainder of a partially processed result set, call SQLCloseCursor or SQLFreeStmt with the fOption parameter set to SQL_CLOSE. 若要完成部分處理的結果集,並測試另一個結果集是否存在,請呼叫 SQLMoreResultsTo finish a partially processed result set and test for the presence of another result set, call SQLMoreResults. 如果 ODBC 應用程式在處理預設結果集之前,嘗試在連接控制碼上執行命令,則呼叫會產生 SQL_ERROR,且呼叫 SQLGetDiagRec 會傳回:If an ODBC application attempts a command on a connection handle before a default result set has been completely processed, the call generates SQL_ERROR and a call to SQLGetDiagRec returns:

szSqlState: "HY000", pfNativeError: 0  
szErrorMsg: "[Microsoft][SQL Server Native Client]  
                Connection is busy with results for another hstmt."  

另請參閱See Also

如何實作資料指標How Cursors Are Implemented