LightSwitch + MySQL error: Nested Transactions are

2020-03-08 06:24发布

问题:

Trying to connect to and modify existing data in a MySQL table. The reading working fine but when trying to save a change, the following error occurs.

An error occurred while starting a transaction on the provider connection. See the inner exception for details. Inner exception message: Nested transactions are not supported.

Using MySQL Connector Net 6.4.3

Answer

I found an answer that works in my case. Add the code below to the datasource code

using System.Transactions;

namespace LightSwitchApplication
{
    public partial class <ChangeThisToYourClassName>
    {
        private TransactionScope tx;

        partial void SaveChanges_Executed()
        {
            tx.Complete();
        }

        partial void SaveChanges_Executing()
        {
            tx = new TransactionScope(TransactionScopeOption.Required, 
                  new TransactionOptions { 
                      IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted
                  });
        } 
    }
}

回答1:

I can confirm that the hotfix works. I got lightswitch working with MySQL using mysql connector.net version 6.4.4. However, when you make your connection and choose your database you'll get this error: "The provider did not return a ProviderManifestToken string."

To fix that, click on the Advanced tab on the connection properties window. Scroll down to the security section and choose true for Persist Security Info.

This allows the entity framework to query the tables.

I created a test app with this and published to my computer and I can also do full crud operations!

Hooray.

P.S. The hotfix for the nested transactions is here: http://archive.msdn.microsoft.com/KB2534087