Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7624455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:58:10+00:00 2026-05-31T04:58:10+00:00

I recently had to switch from using Microsofts SQL server to using MySQL. The

  • 0

I recently had to switch from using Microsofts SQL server to using MySQL.

The application I wrote is using the Entity Framework 4.0. I really like MySQL but the process has been a bit of a pain. Most of the CRUD operations are done with stored procedures so I had fun in my encounter with MySQL bug 55778.

I got over that and manually edited the EDMX file.

Everything worked well until in one scenario I started getting an optimistic concurrency exception.

This is where is happened:

using (var context = new DBEntities())
            {
                context.Requests.AddObject(request);
                context.SaveChanges();

                response.RequestId = request.Id;
                context.Responses.AddObject(response);
                context.SaveChanges();

            } 

The request is logged fine. The exception is thrown when I try to save changes on the response. RequestId is the primary key (not auto incremented) of the response table. I tried to use MySQL profiler to see what was happening but it didn’t really work. I could only profile queries made through my terminal but not queries made by the application running on my local IIS.

I ended up using Wireshark. I found that when I went to save the response the stored procedure linked to Insert on the response Entity was being called. MySQL returned a response saying 0 rows were effected. This caused the exception. The application then called ROLLBACK removing any changes that should have been made.

If I run that stored procedure in a terminal with the exact same values it works.

So over the wire I see this being called:

CALL `DevDB`.`LogResponse` (1,'2012-03-06 12:30',1,1,'test','test','test','test',false,'test');

Then 0 rows effected being returned and a ROLLBACK being called.

Running the very same command from MySQL workbench works. I have tried this multiple times, dropping the database and starting over. I can’t find a reason for this. The request is logged using a similar method and it works.

The application has EXECUTE permissions on both stored routines.

Has anyone come across something like this before?

EDIT:
I also use MySQL handlers to catch any error I could think of and log it to an error log table.
e.g.

DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
    ROLLBACK;
    INSERT INTO `DevDB`.`tblDatabaseErrorLogs`(ERROR_MESSAGE, ERROR_CODE)
    VALUES(
    'SQL Exception at LogResponse',    
    'Unknown'
    );
END; 

So far none to the error codes I planned for – SQL Exception, SQL WARNING and a bunch of others – appear to have happened as the error log table is empty.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:58:11+00:00Added an answer on May 31, 2026 at 4:58 am

    I discovered what was causing the problem but I don’t really understand why. If someone gives a good explanation then I will accept that as the answer to this question rather than accepting my own.

    This is what appears to have caused the problem.

    When using stored procedures to do inserts in the Entity Framework I found that to give the Entity in the application the correct Id at run time I had to return the Id in the stored procedure.

    In MySQL I do it like this:

    CREATE PROCEDURE LogResponse(IN myVals)
    BEGIN 
    Insert Into `DevDB`.`tblResponses`
    (
        someValueNames
    )
    Values
    (
        someValues
    );
    
     SELECT LAST_INSERT_ID() As NewResponseId;
    END
    

    The returned SELECT value maps the the PK Id of the Entity which uses this stored procedure as its INSERT function.

    It just happened that I didn’t use the return value for the response because I didn’t need the Id in the application. This was an oversight I guess but it didn’t raise any issue when I did a similar thing with SQL Server

    i.e.

    SELECT SCOPE_IDENTITY() As NewResponseId
    

    All I did to fix the thing is remove the line

    SELECT LAST_INSERT_ID() As NewResponseId;
    

    Everything appears to be working as it should now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently migrated from a PostgreSQL database to a SQL Server database. To switch
I've recently had to switch from Visual Studio to Eclipse CDT. It would seem
I've recently had to switch encoding of webapp I'm working on from ISO-xx to
I recently had to take a quick look at Adobe InDesign server. In this
I have recently moved from Eclipse 3.4 to 3.5. In 3.4 I had a
Recently had to downgrade a project from .NET 3.5 to .NET 2.0 because it
Recently our Subversion (SVN) server was changed and we did a svn switch .
Up until recently, I had been using Safari 4 for testing and debugging my
I had recently read in a book that using the break statement in say
I recently had a program fail in a production server because the server was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.