Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I keep an OleDbConnection from trying to enlist in a distributed transaction?

I am using OleDB to connect to an excel file using this connection string

@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0 Xml;HDR=YES"""

But when I do this (which is inside a TransactionScope())

using (OleDbConnection conn = new OleDbConnection(connectionString))
{
    conn.Open();
    ...
}

I get the following error

The ITransactionLocal interface is not supported by the 'Microsoft.ACE.OLEDB.12.0' provider. Local transactions are unavailable with the current provider.

How do I make the OleDbConnection not try to enlist in the distributed transaction? The SqlConnection class has a ConnectionString property called 'Enlist', but I can't find an equivalent configuration or method for OleDB.

like image 203
JeremyWeir Avatar asked Oct 09 '09 17:10

JeremyWeir


People also ask

What method inside the OleDbConnection needs to execute to have a connection to the database?

The OleDbConnection is opened and set as the Connection for the OleDbCommand. The example then calls ExecuteNonQuery and closes the connection. To accomplish this, ExecuteNonQuery is passed a connection string and a query string that is an SQL INSERT statement.

What is auto enlistment?

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.

What is the correct form of OleDbConnection syntax?

OleDbConnection("Provider = Microsoft. Jet. OLEDB. 4.0; Data Source = '\\csvFile.

What is OLE DB connection in Excel?

When Excel opens the workbook, it creates an in-memory copy of the OLE DB connection known as the OLEDBConnection object. An OLEDBConnection object contains information related to the connection, such as the name of the server to connect to and the name of the objects to be opened on that server.


1 Answers

In your connection string add the following code : ";OLE DB Services=-4;"

like image 112
Reza Ahang Avatar answered Sep 18 '22 22:09

Reza Ahang