C# How to open a SQL Anywhere connection alongside an Entity Framework connection
<p>I have a C#, .Net 4.5.2 project, built in VS2012, which uses Entity Framework to connect to a SQL database. I now need to access a separate Oracle database, and have been trying to use SQL Anywhere 16 to make the connection. I know that the SQL Anywhere connection works because I have a test project which successfully uses it. The problem is that the <code>connection.Open()</code> method errors with this message:</p>

<blockquote>
  <p>Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool.</p>
</blockquote>

<p>I suspect that Entity Framework doesn't like the additional connection, but enabling MSDTC is not an option as I only have FTP access to the server where the code will live. Is anyone able to suggest an alternative way to get this working, bearing in mind I know very little about Entity Framework?</p>

<h1>Additional</h1>

<p>There aren't any transactions set up as far as I can see (I only wrote the stuff for connecting to the Oracle database), nor is TransactionScope being used. Here's an edited version of my code:</p>

<pre><code>var connectionString = new SAConnectionStringBuilder();
connectionString.Host = "***.***.***.***";
connectionString.DatabaseName = "*****";
connectionString.UserID = "*****";
connectionString.Password = "*****";
connectionString.ServerName = "*****";

using (SAConnection conn = new SAConnection(connectionString))
{
    using (SACommand cmd = conn.CreateCommand())
    {
        cmd.CommandText = query;
            cmd.CommandType = CommandType.Text;
            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();
    }
}
</code></pre>

<h1>Solution</h1>

<p>I did some more searching, and after a bit of trial and error, managed to solve my problem. It seems the SQL Anywhere connection was automatically being put into a transaction. When this was then combined with the transactions being used by the entity framework connection, it was raised to a distributed transaction. </p>

<p>I have found that by putting the connection inside a transaction scope, and using the <code>TransactionScopeOption.Suppress</code> flag, it is no longer being put into a transaction, and therefore does not require MSDTC to be enabled. My code now looks like this:</p>

<pre><code>var connectionString = new SAConnectionStringBuilder();
connectionString.Host = "***.***.***.***";
connectionString.DatabaseName = "*****";
connectionString.UserID = "*****";
connectionString.Password = "*****";
connectionString.ServerName = "*****";

using (TransactionScope scope1 = new TransactionScope(TransactionScope.Suppress))
{
    using (SAConnection conn = new SAConnection(connectionString))
    {
        using (SACommand cmd = conn.CreateCommand())
        {
            cmd.CommandText = query;
                cmd.CommandType = CommandType.Text;
                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
        }
    }

    scope1.Complete();
}
</code></pre>

<p>Thanks to everyone who responded</p>