logo       

Sponsor
FREE Network Mapping Tool for Microsoft® Office Visio® Professional 2007
Don't map your network by hand - let LANsurveyor Exx press for Microsoft Visio Professional 2007 automatically create network diagrams for you!

Regression in MyODBC 3.51.12: msg#00003

db.mysql.odbc

Subject: Regression in MyODBC 3.51.12

Problem:
==========
There's a regression in MyODBC 3.51.12 vs. 3.51.10.


Details:
==========
Using MyODBC with .Net, the OdbcConnection.ConnectionState property no longer
correctly reflects the connection's state.
(It seems to be a side effect of the removal of auto-reconnection logic in
MyODBC.)


How to reproduce:
===================

Test app (C#):
---------------
using System;
using System.Data;
using System.Data.Odbc;

class MySqlConnectTest {
static string user = "INSERT USER HERE";
static string password = "INSERT PASSWORD HERE";
static string server = "INSERT SERVER HERE";

static OdbcCommand connect() {
string c = "Driver={MySQL ODBC 3.51 Driver};Server=" + server +
";Uid=" + user + ";Pwd=" + password + ";OPTION=3";
OdbcConnection conn = new OdbcConnection(c);
conn.Open();
OdbcCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT VERSION()";
return cmd;
}

static void Main(string[] args) {
OdbcCommand cmd;

Console.Out.WriteLine("Opening connection...");
cmd = connect();
cmd.ExecuteNonQuery();

Console.Out.WriteLine("Ok. Kill database or connection now,
then press Enter.");
Console.In.ReadLine();

// Simulate a continuously running program that use only 1
connection=.
for (int i = 5; i > 0; i--) {
try {
if ((cmd.Connection.State |
ConnectionState.Open) == ConnectionState.Open)
Console.Out.WriteLine("Connection state
'" + cmd.Connection.State + "' - executing query.");
else {
Console.Out.WriteLine("Connection state
'" + cmd.Connection.State + "', opening and executing query.");
cmd = connect();
}
cmd.ExecuteNonQuery();
} catch (Exception e) {
Console.Out.WriteLine("Error: " + e.Message +
"\n");
}
}
Console.Out.WriteLine("\nDone - press Enter.");
Console.In.ReadLine();
}
}
---------------

The above test application is similar to application logic that we use to
recreate a connection when it has been closed behind our back for one reason or
another.

You will probably find TCPView from Sysinternals (http://www.sysinternals.com)
handy to simulate a database restart.

1. Compile above C# code with fx. csc.exe.
2. Install MyODBC 3.51.10 or 3.51.12 (run the test once with both).
3. Run test application
4. When it says "kill connection now", use TCPView to close the connection.
5. Observe the difference in behaviour.....


Test results:
===============

MyODBC 3.51.10:
----------------
X:\>MySqlConnectTest.exe
Opening connection...
Ok. Kill database or connection now, then press Enter.
[ Note: killed connection here ]

Connection state 'Open' - executing query.
Connection state 'Open' - executing query.
Connection state 'Open' - executing query.
Connection state 'Open' - executing query.
Connection state 'Open' - executing query.

Done - press Enter.
----------------

Seems MyODBC 3.51.10 reconnects behind our back.
ConnectionState is (correctly) == ConnectionState.Open.

MyODBC 3.51.12:
----------------
X:\>MySqlConnectTest.exe
Opening connection...
Ok. Kill database or connection now, then press Enter.
[ Note: killed connection here ]

Connection state 'Open' - executing query.
Error: ERROR [HYT00] [MySQL][ODBC 3.51 Driver][mysqld-4.1.9-standard-log]MySQL
server has gone away

Connection state 'Open' - executing query.
Error: ERROR [HYT00] [MySQL][ODBC 3.51 Driver][mysqld-4.1.9-standard-log]MySQL
server has gone away

Connection state 'Open' - executing query.
Error: ERROR [HYT00] [MySQL][ODBC 3.51 Driver][mysqld-4.1.9-standard-log]MySQL
server has gone away

Connection state 'Open' - executing query.
Error: ERROR [HYT00] [MySQL][ODBC 3.51 Driver][mysqld-4.1.9-standard-log]MySQL
server has gone away

Connection state 'Open' - executing query.
Error: ERROR [HYT00] [MySQL][ODBC 3.51 Driver][mysqld-4.1.9-standard-log]MySQL
server has gone away

Done - press Enter.
----------------

Seems MyODBC 3.51.12 does _not_ reconnect behind our back.
ConnectionState is (incorrectly) still == ConnectionState.Open.


Workaround:
=============
We've implemented our own ConnectionState mechanism instead of using MyODBC's.


Proposed solution:
====================
I'm imagining that ConnectionState should say "Closed" when the connection has
died behind our back.

The .Net documentation says:
"Calling the State property on an open connection increases application
overhead because each such call results in a SQL_ATTR_CONNECTION_DEAD call to
the underlying ODBC driver to determine if the connection is still valid."

If the assumption is not valid (which IMHO renders ConnectionState somewhat
useless), the SQL_ATTR_CONNECTION_DEAD behaviour should at least be documented
to be "weird".

--
MySQL ODBC Mailing List
For list archives: http://lists.mysql.com/myodbc
To unsubscribe: http://lists.mysql.com/myodbc?unsub=gcdmo-myodbc@xxxxxxxxxxx




<Prev in Thread] Current Thread [Next in Thread>
Sponsor
FREE Network Mapping Tool for Microsoft® OfficeVisio Professional 2007
Don't map your network by hand - let LANsurveyor Express for Microsoft Visio Professional 2007
automatically create network diagrams for you!
Google Custom Search

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation

Home | sitemap | advertise | OSDir is an inevitable website. super tiny logo