Bug #50321 Connecting to mySQL from mobile device throws InvalidOperationException
Submitted: 14 Jan 2010 9:05 Modified: 30 Jan 2010 10:34
Reporter: Peter Micuch Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:Connector-Net 6.2.2 OS:Other (Windows Mobile 5.0 and Windows CE)
Assigned to: Vladislav Vaintroub CPU Architecture:Any
Tags: Mobile Device, Open Connection, TimedStream, Windows CE

[14 Jan 2010 9:05] Peter Micuch
Description:
When I was trying to connect to mySQL database server using my mobile device, I got the following exception:
System.InvalidOperationException was unhandled
  Message="Timeouts are not supported on this stream."
  StackTrace:
       at System.IO.Stream.get_ReadTimeout()
       at MySql.Data.MySqlClient.TimedStream..ctor(Stream baseStream)
       at MySql.Data.MySqlClient.MySqlStream..ctor(Stream baseStream, Encoding encoding, Boolean compress)
       at MySql.Data.MySqlClient.NativeDriver.Open()
       at MySql.Data.MySqlClient.Driver.Open()
       at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
       at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
       at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
       at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
       at MySql.Data.MySqlClient.MySqlPool.GetConnection()
       at MySql.Data.MySqlClient.MySqlConnection.Open()
       at SmartDeviceProject3.Form1.btnLoadData_Click(Object sender, EventArgs e)
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
       at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
       at System.Windows.Forms.Application.Run(Form fm)
       at SmartDeviceProject3.Program.Main()

How to repeat:
1. Have server machine running mySQL server (MySQL Community Server 5.1.42)
2. Try to make connection to the database from your mobile device that runs Windows Mobile 5.0 or Windows CE (I tried both) using Connector-Net 6.2.2 via WLAN
3. You will get exception "Timeouts are not supported on this stream." (see Description for stack trace)

HINT: Make sure that you have corret resources in your MySQL.Data.CF.dll, otherwise you get “Missing Manifest Exception” instead of described exception.

Here a short code snippet:
private void btnLoadData_Click(object sender, EventArgs e)
{
    string aConnString = "SERVER=169.254.81.219;" +
        "DATABASE=test;" +
        "UID=root;" +
        "PASSWORD=root;" + 
        "CONNECTION TIMEOUT=15;";
    MySqlConnection aConnection = new MySqlConnection(aConnString);
    MySqlCommand aCommand = aConnection.CreateCommand();
    MySqlDataReader aReader;
    aCommand.CommandText = "SELECT * FROM parts";
    //!!!Following line throws the exception!!!
    aConnection.Open();
...

Suggested fix:
When I downgraded to version 6.1.3 of the .NET connector, I was able to connect and view data, so I guess this is only 6.2.* problem so far.

From what I can see, there is a difference in the MySqlStream constructor between versions 6.1.3 and 6.2.2. A TimedStream is created now in 6.2.2 and this tries to access Stream.ReadTimeout where the exception occurs. I am not sure whether this is supported on Windows Mobile or Windows CE.
[14 Jan 2010 10:21] Tonci Grgin
Hi Peter and thanks for your report.

The problem might be related to Bug#40684 and Bug#31996. Will consult Wlad if the patches were tested against CF.
[15 Jan 2010 19:20] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/97157

824 Vladislav Vaintroub	2010-01-15
      Bug #50321 Connecting to mySQL from mobile device throws InvalidOperationException.
      fix is to avoid accessing stream.readTimeout and streamWritetimeout properties on CF.
[15 Jan 2010 19:20] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/97158

824 Vladislav Vaintroub	2010-01-15
      Bug #50321 Connecting to mySQL from mobile device throws InvalidOperationException.
      fix is to avoid accessing stream.readTimeout and streamWritetimeout properties on CF.
[18 Jan 2010 6:48] Tonci Grgin
Thanks Wlad.
[21 Jan 2010 16:08] Tony Bedford
An entry has been added to the 6.2.3 changelog:

When using the Compact Framework the following exception occurred when attempting to connect to a MySQL Server:

System.InvalidOperationException was unhandled
  Message="Timeouts are not supported on this stream."
[30 Jan 2010 10:34] Peter Micuch
Thank you guys, I will try your fix soon hopefully.
[20 Oct 2023 8:16] Stefan Heisl
Hey there,

I've encountered a similar issue when attempting to connect to a MySQL server from a mobile device. The error you're seeing, "Timeouts are not supported on this stream," is indeed perplexing. It appears to be related to the .NET connector version 6.2.*.

Your detective work in downgrading to version 6.1.3 seems to have led you in the right direction. It's possible that there's a compatibility issue between version 6.2.2 and Windows Mobile/Windows CE. The key difference you highlighted in the MySqlStream constructor might be the root of the problem. 

As a workaround, continuing to use version 6.1.3 could be a viable solution until a more compatible update is released. Alternatively, you can consider reaching out to the MySQL Connector/NET community for any patches or updates specific to mobile environments. I read about it here and I hope it works: https://www.gizmochina.com/guides/smartphones-of-the-future-whats-next/

This issue is quite technical, but your experience and observations are undoubtedly valuable for others encountering the same hiccup. Thanks...