Hi,
Half the time my page loads (which use bytefx mysql), it
throws this error:
Cannot access a disposed object
named "System.Net.Sockets.NetworkStream". Object
name: "System.Net.Sockets.NetworkStream".
Here is where it happens, I know it says nothing to you
guys, but it's the line 64 on the Close() method. See
below for stack trace.
Source Error:
Line 62: finally
Line 63: {
Line 64: con.Close();
Line 65: }
Line 66: }
This is why I'm writing to you, because I think it might
be in the mysql data driver itself!
Stack Trace:
[ObjectDisposedException: Cannot access a disposed
object named "System.Net.Sockets.NetworkStream".
Object name: "System.Net.Sockets.NetworkStream".]
System.Net.Sockets.NetworkStream.Read(Byte[]
buffer, Int32 offset, Int32 size)
System.IO.Stream.ReadByte() +38
ByteFX.Data.MySqlClient.Driver.ReadPacketFromServer
()
ByteFX.Data.MySqlClient.Driver.ReadPacket()
ByteFX.Data.MySqlClient.CommandResult.Clear()
ByteFX.Data.MySqlClient.MySqlDataReader.Close()
ByteFX.Data.MySqlClient.MySqlConnection.Close()
XNet.UserControls.ProjectsList.BindDataGrid() in
c:\inetpub\wwwroot\xnet\usercontrols\projectslist.ascx.c
s:64
XNet.Web.ProjectsList.Page_Load(Object sender,
EventArgs e) in
c:\inetpub\wwwroot\xnet\projectslist.aspx.cs:27
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750
Logged In: YES
user_id=1288061
I finally found more information.
I got a method that is called BindDataGrid()
which opens a MySqlConnection object and do an
ExecuteReader from a MySqlCommand then call the
DataBind method of a datagrid.
The problem occurs when in the ItemDataBound event of that
datagrid, I open another MySqlConnection to perform some
business logic (so instead of displaying IdGroup 1, I query the
DB to get the actual Group name) then close the connection.
when I get back to the original method BindDataGrid() and try
to close the connection, it says Can't access a disposed
object as describe in my previous post.
Hope this helps!
Logged In: YES
user_id=1288061
Here is my proof of concept
private void Button1_Click(object sender, System.EventArgs
e)
{
string mySQL = "SELECT * FROM Clients";
(ConfigurationSettings.AppSettings["ConnectionString"]);
MySqlCommand cmd = new MySqlCommand
(mySQL, con);
cmd.ExecuteReader(CommandBehavior.CloseConnection);
new MySqlConnection(ConfigurationSettings.AppSettings
["ConnectionString"]);
* FROM Clients";
MySqlCommand cmd2 =
new MySqlCommand(mySQL2, con2);
(CommandBehavior.CloseConnection);
dr2.Read();
["IdClient"].ToString();
}
finally
{
con2.Close(); // I
think this line closes both connection and make it so that
both MySqlConnection get disposed!
}
}
}
ConnectionState.Closed)
con.Close();
}
}
Logged In: YES
user_id=523261
I'm sorry but I no longer provide support for this project. This
code was acquired by MySQL in April 2004. The latest
version can be found at www.mysql.com