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

  • SEARCH
  • Home
  • 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 843545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:08:45+00:00 2026-05-15T06:08:45+00:00

I am using SubSonic 2.1 and entcountered a problem while executing a Transaction with

  • 0

I am using SubSonic 2.1 and entcountered a problem while executing a Transaction with

SharedDbConnectionScope and TransactionScope.
The problem is that in the obj.Save() method I get an “The connection must be valid and open” exception

I tracked down the problem to this line:

// Loads a SubSonic ActiveRecord object
User user = new User(User.Columns.Username, "John Doe");

in this Constructor of the User class a method “LoadParam” is called which eventually does

if (rdr != null)
    rdr.Close();

It looks like the rdr.Close() implicitly closes my connection which is fine when using the AutomaticConnection. But during a transaction it is usally not a good idea to close the connection 🙂

My Question is if this is by design or if it’s an error in the MySqlDataReader.

  • 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-15T06:08:46+00:00Added an answer on May 15, 2026 at 6:08 am

    That was tricky!
    After a bit debugging I found the following method in the SubSonic2 MySqlDataReader.cs file:

        public override IDataReader GetReader(QueryCommand qry)
        {
            AutomaticConnectionScope conn = new AutomaticConnectionScope(this);
    
            ...
    
            cmd.Connection = (MySqlConnection)conn.Connection;
    
            IDataReader rdr;
    
            try
            {
                rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            }
            catch(MySqlException x)
            {
                conn.Dispose();
                throw x;
            }
    
            ...
        }
    

    Which is wrong since I am using a SharedDbConnection. In the SqlDataProvider it has been fixed already but not for MySqlDataReader.

    It should look like this:

            try
            {
                // if it is a shared connection, we shouldn't be telling the reader to close it when it is done
                rdr = conn .IsUsingSharedConnection ?
                          cmd.ExecuteReader() : 
                          cmd.ExecuteReader(CommandBehavior.CloseConnection);
            }
            catch (MySqlException)
            {
                // AutoConnectionScope will figure out what to do with the connection
                conn.Dispose();
                //rethrow retaining stack trace.
                throw;
            }
    

    Pretty heavy bug, it rendered Querying in a Transaction impossible (I must admit I never needed this before).

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

Sidebar

Related Questions

While using SubSonic 3 I wrote the below. I thought I would get user_ref
I'm using Subsonic 3.0.0.3 with ActiveRecord, running against a MySQL database. I'm finding that
I've been using SubSonic.Query all these while, until one day when I can't do
I want to execute the following query using Subsonic: SELECT MAX([restore_date]) FROM [msdb].[dbo].[restorehistory] While
Using SubSonic 3 ActiveRecord, I generated code from an existing database that had foreign
Using Subsonic 2.1 I want to make my method call to results look like
im using subsonic 3.0.0.3 activerecord and everything is fine and i get no error
I am using SubSonic 3.0.0.3 (the ActiveRecord approach) in an HttpHandler that I have
I'm interested in using Subsonic 3.0 for developing a new ASP.Net MVC application that
I have begun using SubSonic and I am wondering how to get it to

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.