Problem with non-closed connation in MySQLDirect .NET Mobile 3.20

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
GEORGE_GR
Posts: 4
Joined: Tue 06 Dec 2005 22:33

Problem with non-closed connation in MySQLDirect .NET Mobile 3.20

Post by GEORGE_GR » Thu 13 Apr 2006 14:53

Hello all,

I try to separate database code from main application code. I have module with public class MySQLData and the static methods therein. Ther is a method listed below:

Code: Select all

.....
public class ParametersList
    {
        private string PName;
        private object PValue;
        public ParametersList(string pm, object pv)
        {
            this.PName = pm;
            this.PValue = pv;
        }
        #region Properties

        public string ParameterName    // usually id field
        {
            get { return this.PName;}
            set { this.PName = value; }
        }

        public object Value  // any string field
        {
            get { return this.PValue;}
            set { this.PValue = value; }
        }
        #endregion
    }

......

public static IDataReader SelectSQL(string CmdName, ParametersList[] pl)
    {
        MySqlConnection cnn = new MySqlConnection (AppConfig.AppSettings["ConnectionString"]);
        IDataReader idr = null;
        MySqlCommand mcd = new MySqlCommand(CmdName, cnn);
        mcd.CommandType = CommandType.StoredProcedure;
        for (int i = 0; i < pl.Length; i++)
            mcd.Parameters.Add(pl[i].ParameterName,pl[i].Value);
        try
        {
            cnn.Open();
            idr = mcd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        catch (Exception Err)
        {
            MessageBox.Show("MySQL Error: " + Err.Message);
        }
        return idr;
    }
I call this method from main program like this:

Code: Select all

private void btnTest_Click(object sender, EventArgs e)
        {
string strTest=null;
ParametersList[] pl = new ParametersList[1];
IDataReader midr = null;
pl[0] = new ParametersList("myid", 456);
midr=MySQLData.SelectSQL("test", pl);
while(midr.Read()) strTest+=midr.GetValue(2).ToString();
midr.Close();
MessageBox.Show(strTest);
}
This code runs pretty good only at first time. At second time it throws an odd and unrelated exception that I guess is because of non-closed connection.


The question is WHY ?
I use CommandBehavior.CloseConnection and theoretically the connection must be closed.

GEORGE_GR
Posts: 4
Joined: Tue 06 Dec 2005 22:33

I anwer my question !

Post by GEORGE_GR » Thu 13 Apr 2006 15:25

There is no problem with non-closed connection. Connections are always closed.
The problem was because I initialize the ConnectionString from NameValueCollection (AppConfig.AppSettings).
Now i'm looking for the cause ?

Alexey
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Post by Alexey » Fri 14 Apr 2006 07:06

We could not reproduce the problem. Please provide us with the text of your stored procedure.
What is the full text of the exception.

GEORGE_GR
Posts: 4
Joined: Tue 06 Dec 2005 22:33

Post by GEORGE_GR » Fri 14 Apr 2006 08:52

The problem was solved. Thanks for your attention.

Post Reply