Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is Enlist=false means in connection string for sql server?

I am a beginner with .net. I faced issue with the following error

"The transaction operation cannot be performed because there are pending requests working on this transaction.".

i read somewhere in the blog .i appended my connection string with enlist=true and the issue was resolved.

Note: i am upgrading my DB from sql server 2005 to sql server 2008R2.

Please help to understand the importance of using enlist.

like image 953
Supriyo Bhattacherjee Avatar asked Mar 01 '16 06:03

Supriyo Bhattacherjee


People also ask

What is enlist false in connection string?

If Enlist = “true” indicates that the SQL Server connection pooler automatically enlists the connection in the creation thread's current transaction context. If Enlist=”false”, SqlClient connections do not interact with the transaction.

What should be the connection string for SQL Server?

The following connection string will connect the database using windows authentication. Server=ServerName;Database=DatabaseName;Trusted_Connection=True; With help of the following C# code, this is how we can see the usage of a connection string in an application.

How can I set an SQL Server connection string?

Right-click on your connection and select "Properties". You will get the Properties window for your connection. Find the "Connection String" property and select the "connection string". So now your connection string is in your hands; you can use it anywhere you want.

What is ConnectionString property?

The value of the ConnectionString property is a connection string that includes the source database name and the parameters you need to establish the connection. The default value of the ConnectionString property is an empty string. The Server attribute is mandatory in all situations.


2 Answers

Enlisting is user for Distributed Transaction

The Connection object will automatically enlist in an existing distributed transaction if it determines that a transaction is active. Automatic transaction enlistment occurs when the connection is opened or retrieved from the connection pool. You can disable auto-enlistment in existing transactions by specifying Enlist=false as a connection string parameter for a SqlConnection, or OLE DB Services=-7 as a connection string parameter for an OleDbConnection.

Note The Connection must be open before calling EnlistDistributedTransaction.

Here is an example for you with Enlist=False;

like image 158
sujith karivelil Avatar answered Oct 17 '22 08:10

sujith karivelil


The MSDN says:

The ConnectionString property supports a keyword, Enlist, which indicates whether System.Data.SqlClient will detect transactional contexts and automatically enlist the connection in a distributed transaction. If Enlist=true, the connection is automatically enlisted in the opening thread's current transaction context. If Enlist=false, the SqlClient connection does not interact with a distributed transaction. The default value for Enlist is true. If Enlist is not specified in the connection string, the connection is automatically enlisted in a distributed transaction if one is detected when the connection is opened.

like image 35
Rahul Tripathi Avatar answered Oct 17 '22 06:10

Rahul Tripathi