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.