WHERE clause specifying date range causing "Connection must be valid and open" error
Posted by: Grommit Wallace
Date: July 16, 2005 09:09PM

I've simplified my question from a prior posting. I'm using MySQL 4.1.11 and MySQL Connector NET 1.0.4 on Windows XP SP2.

The following query works when issued via MySQL Query Browser:
"SELECT * FROM Events WHERE Eventdate >= '2005-07-01 08:00:00Z' AND Eventdate <='2005-07-01 09:00:00Z'"

So the query is syntatically and logically correct.

Yet when my code tries to fill a Dataset with the results of the above query using the following code:
string CS = "Database=abc;Data Source=localhost;User Id=grommit;Password=wallace;";
MySqlConnection conn = new MySqlConnection(CS);
conn.Open();
MySqlDataAdapter da = new MySqlDataAdapter(sql, conn); // sql = query above
DataSet ds = new DataSet();
da.Fill(ds); // Exception thrown here...

I get an error on the line "da.Fill(ds)" :
"System.InvalidOperationException:Connection must be valid and open." is thrown when the following query is issued:

The above code works great for other queries. It's when I add "WHERE Eventdate >= '2005-07-01 08:00:00Z' AND Eventdate <='2005-07-01 09:00:00Z'" that the error appears.

What am I doing wrong? Help....

FYI: The table Events used in the query above is defined as:
CREATE TABLE `events` (
`Id` varchar(36) NOT NULL default '',
`EventDate` datetime NOT NULL default '0000-00-00 00:00:00',
`DetailId` varchar(36) NOT NULL default '',
`RecurrenceId` varchar(36) default NULL,
`Active` tinyint(1) default NULL,
....

Options: ReplyQuote


Subject
Written By
Posted
WHERE clause specifying date range causing "Connection must be valid and open" error
July 16, 2005 09:09PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.