Description of multipleactiveresultsets of SQL Server Data Link strings

Source: Internet
Author: User

A recent project is about the synchronization of different databases. Considering the timeliness of dataProgramAdded multipleactiveresultsets to the database link string;

Multipleactiveresultsets is used to specify whether the result set of multiple activities is associated with the specified link; the type is bool; true indicates that the result set is associated with the specified link; false indicates that the result set is not associated with the specified link; the default value is false;

For example ):

View code

Sqlconnectionstringbuilder sb = New  Sqlconnectionstringbuilder (); sb. datasource = "  .  "  ; Sb. initialcatalog = "  Neo_oa "  ; Sb. integratedsecurity = True  ;  Using (Sqlconnection con = New  Sqlconnection (sb. connectionstring )){  String SQL = "  Select count (0) from userinfo  "  ; Sqlcommand cmd = New Sqlcommand (SQL, con); con. open ();  Object Ob = Cmd. executescalar ();  If (Ob = Null  ) {Console. writeline (  0  );}  Else  {Console. writeline (convert. toint32 (OB) ;}} console. Readline (); 

Use the storage process sp_who provided by SQL Server to monitor our process information;

Open multiple EXE files under our dug file and execute the storage process sp_who in SQL Server. At this time, we will find that in the display list, multiple dbnames appear in neo_oa (I use this database.

We can see that the database has been established for multiple times;

Modify the above program:

View code

Sqlconnectionstringbuilder sb = New  Sqlconnectionstringbuilder (); sb. datasource = "  .  "  ; Sb. initialcatalog = "  Neo_oa  " ; Sb. integratedsecurity = True  ; Sb. multipleactiveresultsets = True  ;  Using (Sqlconnection con = New  Sqlconnection (sb. connectionstring )){  String SQL = "  Select count (0) from userinfo  "  ; Sqlcommand cmd = New  Sqlcommand (SQL, con); con. open ();  Object Ob = Cmd. executescalar ();  If (Ob = Null  ) {Console. writeline (  0  );}  Else  {Console. writeline (convert. toint32 (OB) ;}} console. Readline (); 

Still according to the steel method, it is found that at this time there are no multiple cases that dbname is neo_oa, that is, reuse the Link Used for the first open.

Opening and disabling databases consume system performance. Using this connection method can reduce the burden on the system.

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.