Question

I'm trying to get my MVC3 application to use MySql database instead of Sql Server 2008. I have created the associated database and objects in Mysql. And Updated the connection string in my web.config file to reference MySql.Data.MySqlClient.

When I run my application and try to login, I am getting the error

Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.

I have a custom MembershipProvider and within the validation process I have the following

 using (MyContext context= new MyContext())
 {
      --some checks here
      ---
        if (verificationSucceeded)
        {
            user.passwordFailuresSinceLastSuccess = 0;
        }
        else
        {
            int failures = user.passwordFailuresSinceLastSuccess;
            if (failures != -1)
            {
                user.passwordFailuresSinceLastSuccess += 1;
                user.lastPasswordFailureDate = DateTime.UtcNow;
            }
        }
        context.SaveChanges();  ----THIS IS WHERE IT FALLS OVER
         -- some other code here 
    }

The above code works perfectly well with Sql Server 2008, but is falling over only with MySql. Any idea how I can resolve this please?

I do not have any triggers defined on the underlying table btw. The application is MVC3 with EF Code First. Thanks,

Was it helpful?

Solution

If anybody else is having this issue, the problem was with the Guid as I though. To get over this, add the following to your connection string

Old Guids=true

So for example, my connection string looks like this now.

<add name="MyDB" connectionString="Server=localhost; Database=mydatabase; Uid=user; Pwd=mypass; Old Guids=true;" providerName="MySql.Data.MySqlClient" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top