Bug #7125 Probable BUG after connection lost
Submitted: 9 Dec 2004 11:00 Modified: 19 Sep 2007 12:24
Reporter: Emanuele Frisoni Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / ODBC Severity:S1 (Critical)
Version:3.51.10 OS:Windows (Win2000)
Assigned to: CPU Architecture:Any

[9 Dec 2004 11:00] Emanuele Frisoni
Description:
Hi people, 
I'm connecting to my MySQL db on Linux RH9.1 through MyODBC 3.51.06 from Win2000 with program written in C#. 
Following the source code of library I'm written down to execute queries: 

public void Select(string sql_what, string sql_from, string sql_clause) 
{ 
//E.g. Select("Colonna_1, Colonna_2", "Tabella_1", "Colonna_1 = 'pippo'") 
string select_sql = "SELECT "+sql_what+" FROM "+sql_from+" "+sql_clause; 
bool ok = false; 
int retries = 0; 

while ((!ok) && (retries < n_max_retries)) 
{ 
ok = false; 
try 
{ 
OdbcConnection dbConn = new OdbcConnection("DSN=mydb;"); 
dbConn.Open(); 
OdbcCommand myAccessCommand = new OdbcCommand(select_sql, dbConn); 
OdbcDataAdapter myDataAdapter = new OdbcDataAdapter(myAccessCommand); 
myDataSet = new DataSet(); 
try 
{ 
myDataAdapter.Fill(myDataSet, sql_from); // $$$$ HERE IS ERROR 
ok = true; 
} 
catch 
{ 
ok = false; 
} 
finally 
{ 
myDataAdapter.Dispose(); 
dbConn.Close(); 
} 
currentTable = myDataSet.Tables[sql_from]; 
} 
catch //(Exception e) 
{ 
ok = false; 
} 
retries++; 
} 
if (!ok) 
{ 
// server disconnected; 
throw new ApplicationException("Select server Error"); 
} 
} 

The problem consists in that: 
1 - first of all I try to get data from the server correctly 
2 - then I disconnect the LAN 
3 - when I try to get other data from the server the program blocks to 
>>> myDataAdapter.Fill(myDataSet, sql_from); // $$$$ HERE IS ERROR 
with no exceptions thrown!!! neither error code returned back!!! 

Thanks.

How to repeat:
Hi people, 
I'm connecting to my MySQL db on Linux RH9.1 through MyODBC 3.51.06 from Win2000 with program written in C#. 
Following the source code of library I'm written down to execute queries: 

public void Select(string sql_what, string sql_from, string sql_clause) 
{ 
//E.g. Select("Colonna_1, Colonna_2", "Tabella_1", "Colonna_1 = 'pippo'") 
string select_sql = "SELECT "+sql_what+" FROM "+sql_from+" "+sql_clause; 
bool ok = false; 
int retries = 0; 

while ((!ok) && (retries < n_max_retries)) 
{ 
ok = false; 
try 
{ 
OdbcConnection dbConn = new OdbcConnection("DSN=mydb;"); 
dbConn.Open(); 
OdbcCommand myAccessCommand = new OdbcCommand(select_sql, dbConn); 
OdbcDataAdapter myDataAdapter = new OdbcDataAdapter(myAccessCommand); 
myDataSet = new DataSet(); 
try 
{ 
myDataAdapter.Fill(myDataSet, sql_from); // $$$$ HERE IS ERROR 
ok = true; 
} 
catch 
{ 
ok = false; 
} 
finally 
{ 
myDataAdapter.Dispose(); 
dbConn.Close(); 
} 
currentTable = myDataSet.Tables[sql_from]; 
} 
catch //(Exception e) 
{ 
ok = false; 
} 
retries++; 
} 
if (!ok) 
{ 
// server disconnected; 
throw new ApplicationException("Select server Error"); 
} 
} 

The problem consists in that: 
1 - first of all I try to get data from the server correctly 
2 - then I disconnect the LAN 
3 - when I try to get other data from the server the program blocks to 
>>> myDataAdapter.Fill(myDataSet, sql_from); // $$$$ HERE IS ERROR 
with no exceptions thrown!!! neither error code returned back!!! 

Thanks.

Suggested fix:
To work around the problem I have inserted a Server check before the DataAdapter.Fill method which opens a socket to the Http port. If the server doesn't respond an ApplicationException will be thrown.

Here is the code:

public void CheckServer(string url)
    {
      System.Text.Encoding ASCII = System.Text.Encoding.ASCII;
      string Get = "GET / HTTP/1.1\r\nHost: " + url + 
                    "\r\nConnection: Close\r\n\r\n";
      Byte[] ByteGet = ASCII.GetBytes(Get);
      Byte[] RecvBytes = new Byte[256];
      IPEndPoint EPhost = new IPEndPoint(IPAddress.Parse(url), 80);
      Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
      s.Connect(EPhost);
      if (!s.Connected)
      {
        throw new ApplicationException("Unable to connect to host");
      }
      s.Close();
    }

public void Select(string sql_what, string sql_from, string sql_clause) 
{ 
//E.g. Select("Colonna_1, Colonna_2", "Tabella_1", "Colonna_1 = 'pippo'") 
string select_sql = "SELECT "+sql_what+" FROM "+sql_from+" "+sql_clause; 
bool ok = false; 
int retries = 0; 

while ((!ok) && (retries < n_max_retries)) 
{ 
ok = false; 
try 
{ 
OdbcConnection dbConn = new OdbcConnection("DSN=mydb;"); 
dbConn.Open(); 
OdbcCommand myAccessCommand = new OdbcCommand(select_sql, dbConn); 
OdbcDataAdapter myDataAdapter = new OdbcDataAdapter(myAccessCommand); 
myDataSet = new DataSet(); 
try 
{ 
CheckServer(url_server);
myDataAdapter.Fill(myDataSet, sql_from); // $$$$ HERE IS ERROR 
ok = true; 
} 
catch 
{ 
ok = false; 
} 
finally 
{ 
myDataAdapter.Dispose(); 
dbConn.Close(); 
} 
currentTable = myDataSet.Tables[sql_from]; 
} 
catch //(Exception e) 
{ 
ok = false; 
} 
retries++; 
} 
if (!ok) 
{ 
// server disconnected; 
throw new ApplicationException("Select server Error"); 
} 
}
[3 Jun 2007 22:35] Julien Wadin
I confirm this very annoying behaviour !