S h o r t S t o r i e s

// Tales from software development

Archive for June 2011

MySQL Connector/NET hangs on MySqlDataReader.Read()

leave a comment »

I was testing some changes in a data interface that runs as a Windows Service and reads configuration data from a MySQL database. Three different sets of data are read when the service starts and while the first two loaded successfully the third was causing the service to hang.

This was strange because the interface has been running in a live environment for over a year and I hadn’t made any changes in this part of the code.

I executed the stored procedure being called in MySQL QueryBrowser and it returned 42 rows. I restarted the service under the debugger and single-stepped through the calls to MySqlDataReader.Read(). It successfully read the 42 rows and then hung on the next call to Read().

I couldn’t see any reason why the Read() was hanging so, in desperation, I downloaded the latest build of the MySQL Connector/NET, 6.3.6, and replaced the version the service was using, 6.0.3. The good news was that the final call to Read() now failed with a System.Timeout exception rather than hanging forever. The exception message was:

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

A timeout on the final Read() didn’t make any sense but it was better than a hang.

I added SQL_BUFFER_RESULT to the query being executed in the stored procedure in the hope that this might solve a buffering problem, if that’s what this was. Now the service failed before the first read with a MySqlException with the following error message:

Subquery returns more than 1 row

This was beginning to make a bit of sense now. I went back to Query Browser and looked at the status area at the bottom of the window and sure enough there was the same error message: Subquery returns more than 1 row

Previously, I’d just seen the 42 rows returned and thought the stored procedure was executing successfully.

So, the problem was that the query returned 42 rows and then failed because of the problem with the subquery. When SQL_BUFFER_RESULT was specified the error occurred before any of the rows were sent to the client.

It seems that there’s a bug here in the Connector/NET. An error that occurs after the first result rows are sent to the client doesn’t necessarily throw an exception. In 6.0.3 the Read() where the error occurs hangs the application while in 6.3.6 it causes a hang that times out and a System.Timeout exception is thrown.

Written by Sea Monkey

June 22, 2011 at 8:00 pm

Posted in Debugging, Development

Tagged with , ,

Fail quickly, fail small…

leave a comment »

Tim Harwood, author of Adapt, was interviewed on Start The Week this morning and came up with the pithy advice: “Fail quickly, fail small”.

The alternative, as demonstrated by the banks a couple of years ago, is to fail late and fail big.

Written by Sea Monkey

June 20, 2011 at 8:00 pm

Posted in General

Tagged with

Kindle for PC 4: Book could not be opened

leave a comment »

Without any prompting, Kindle for PC updated itself to version 1.3.0 the other day. When I tried to open one of the books I’d downloaded to the PC I got a message saying “Book could not be opened”  and suggesting that I remove it from the device and download it again. I tried this but it made no difference. I tried to open a few other books and realised that most of them couldn’t be opened either although there were a few that opened successfully.

From previous experience, I know that Amazon’s DRM limits you to a certain number of device downloads for each book. I didn’t think that I’d exceeded this but when I went to the ‘Manage your devices’ page on the Amazon web site I realised what had happened.

To help me identify which device registration was which, I’d renamed each registration shown from the default of ‘Kindle for PC’ to ‘computer-name Kindle for PC’. When the latest version of Kindle was installed it created a new device registration for the PC using the new default name of ‘Kindle for PC 4’. So I now had two device registrations for the PC I was trying to open the book on and, as far as the Amazon DRM was concerned, both device registrations appeared to have a copy of the book I was trying to open. Amazon’s DRM decided that I had exceeded the number of downloaded copies of the book and refused to allow me to open it.

I simply deleted the old registration which was no longer being used and then successfully opened the book on my PC.

Written by Sea Monkey

June 16, 2011 at 8:00 pm

Posted in General

Tagged with