What is the MARS result set in SQLSERVER?

Source: Internet
Author: User
MARS: Interpretation of multiple active result sets on MSDN: SQLServer2005 introduced support for multiple active result sets in Database Engine access applications. In earlier versions of SQLServer, database applications cannot maintain multiple active statements on a single connection. When using SQLServer default result set, the application must first

MARS: Interpretation of multiple active result sets on MSDN: SQL Server 2005 introduces support for multiple active result sets in Database Engine access applications. In earlier versions of SQL Server, database applications cannot maintain multiple active statements on a single connection. When using the default result set of SQL Server, the application must first

MARS: Multiple Active result sets

Description on MSDN:

SQL Server 2005 introduces support for multiple active result sets (MARS) in Database Engine access applications. In earlier versions of SQL Server, database applications cannot maintain multiple active statements on a single connection. When using the default result set of SQL Server, the application must process or cancel all result sets generated by a batch of processing before executing any other batch processing on the connection. SQL Server 2005 introduces new connection attributes and supports applications with multiple pending requests on each connection. In particular, it supports the default result set with multiple activities for each connection.

MARS simplifies application design with the following new features:

  • Applications can open multiple default result sets at the same time and read them in an staggered manner.

  • Applications can execute other statements (such as INSERT, UPDATE, DELETE, and stored procedure calls) when the default result set is opened ).

The following guidelines are helpful for applications using MARS:

  • The default result set should be used to generate short-term or small result sets using a single SQL statement (SELECT, DML with OUTPUT, RECEIVE, READ TEXT, etc.

  • Server cursors should be used to generate long-term or large result sets using a single SQL statement.

  • Process requests (whether or not they return results) and batches that return multiple results should always be read to the end of their results.

  • Use APIs instead of Transact-SQL statements to change Connection Properties and manage transactions.

  • In MARS, simulation within the session range is prohibited when multiple batches are concurrently run.

In SQL2000, only one batch processing command can be run for one connection at the same time. That is to say, a connection can only have one request running at a time point.

However, after SQL2005, if the MARS technology is used, multiple result sets can be enabled for one connection at the same time. The sys. sysprocesses view cannot
Correctly display this behavior.

MARS execution method:

MARS is fromStaggered executionInsteadParallel ExecutionAngle defined

How to Use the MARS technology in different data access interfaces

If you use the SQL Server Native Client OLE DB access interface ADO and ADO. NET, this interface is used.

The connection string can be like this:

1 string connstr = "Server=(local);Database=AdventureWorks;User ID=sa;Password=test;MarsConn=true";

If you use the SQL Server Native Client ODBC driver

The connection string can be like this:

1 SQLSetConnectAttr(hdbc, SQL_COPT_SS_MARS_ENABLED, SQL_MARS_ENABLED_YES, SQL_IS_UINTEGER);2 SQLDriverConnect(hdbc, hwnd,"DRIVER=SQL Server Native Client 10.0;SERVER=(local);trusted_connection=yes;", SQL_NTS, szOutConn, MAX_CONN_OUT, &cbOutConn, SQL_DRIVER_COMPLETE);
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.