Skip to content

Latest commit

 

History

History
77 lines (60 loc) · 2.85 KB

how-to-disable-multiple-active-resultsets-mars.md

File metadata and controls

77 lines (60 loc) · 2.85 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic helpviewer_keywords
How to: disable multiple active resultsets (MARS)
Learn how to disable Multiple Active Resultsets support when using the Microsoft Drivers for PHP for SQL Server
David-Engel
davidengel
08/10/2020
sql
connectivity
conceptual
multiple active result sets, disabling
MARS, disabling

How to: Disable Multiple Active Resultsets (MARS)

[!INCLUDEDriver_PHP_Download]

If you need to connect to a SQL Server data source that does not enable Multiple Active Result Sets (MARS), you can use the MultipleActiveResultSets connection option to disable or enable MARS.

Procedure

To disable MARS support

  • Use the following connection option:

    'MultipleActiveResultSets'=>false  
    

    If your application attempts to execute a query on a connection that has an open active result set, the second query attempt will return the following error information:

    The connection cannot process this operation because there is a statement with pending results. To make the connection available for other queries either fetch all results, cancel or free the statement. For more information about the MultipleActiveResultSets connection option, see Connection Options.

SQLSRV example

The following example shows how to disable MARS support, using the SQLSRV driver of the [!INCLUDEssDriverPHP].

<?php  
/* Connect to the local server using Windows Authentication and  
specify the AdventureWorks database as the database in use. */  
$serverName = "MyServer";  
$connectionInfo = array( "Database"=>"AdventureWorks", 'MultipleActiveResultSets'=> false);  
$conn = sqlsrv_connect( $serverName, $connectionInfo);  
if( $conn === false )  
{  
   echo "Could not connect.\n";  
   die( print_r( sqlsrv_errors(), true));  
}  
  
sqlsrv_close( $conn);  
?>  

PDO_SQLSRV example

The following example shows how to disable MARS support, using the PDO_SQLSRV driver of the [!INCLUDEssDriverPHP].

<?php  
// Connect to the local server using Windows Authentication and AdventureWorks database  
$serverName = "(local)";   
$database = "AdventureWorks";  
  
try {  
   $conn = new PDO(" sqlsrv:server=$serverName ; Database=$database ; MultipleActiveResultSets=false ", NULL, NULL);   
   $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );   
}  
  
catch( PDOException $e ) {  
   die( "Error connecting to SQL Server" );   
}  
  
$conn = null;   
?>  

See Also

Connecting to the Server