Database connection multiplexing Multipleactiveresultsets=true

Source: Internet
Author: User
Tags management studio

Multipleactiveresultsets can make database connections reusable. This will not be afraid of the database connection resources are depleted. The use of the method is simple, just add it to the data connection string.

For example: server= (local), integrated security = True;database=adventureworks; Multipleactiveresultsets=true;

Test Cases:

Using System; Using System.Threading; Using System.Data.SqlClient; Using System.Configuration; Namespace ConsoleApplication1 {public class Example {public static void Main () {SqlConnection sql1 = new SqlConnection ( "Server= (local), integrated security = True;database=adventureworks;"); SQL1. Open (); SqlCommand comm1 = new SqlCommand (); Comm1.commandtext = "Select 1"; Comm1.commandtype = System.Data.CommandType.Text; Comm1. Connection = SQL1; Comm1. ExecuteNonQuery (); SQL1. Close (); Console.ReadLine (); } } }

After compiling, open the Bin/debug/consoleapplication1.exe.

Open a new window in SQL Server 2008 Management Studio, enter sp_who

By F5 execution, you can see that a user is already connected to the AdventureWorks database.

Then open a ConsoleApplication1.exe and find that one more user will be connected to the AdventureWorks database.

Now change the connection string of the program to server= (local), integrated security = True;database=adventureworks; Multipleactiveresultsets=true;

Executed in the order above, it is found that no user or only one user is connected to the AdventureWorks database, regardless of how many ConsoleApplication1.exe are open.

This is the benefit of database connectivity reuse.

For additional uses of database connection strings, see:

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.