Bug #21402 System.Net.Sockets.SocketException
Submitted: 1 Aug 2006 18:51 Modified: 8 Aug 2006 10:48
Reporter: Gerry Cote Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:1.0.7 OS:Windows (Windows XP)
Assigned to: CPU Architecture:Any

[1 Aug 2006 18:51] Gerry Cote
Description:
Using:
- .NET connector 1.0.7
- MySQL Server 4.1.14
- Tried compiling using VS .NET 2003 and 2005
- Windows XP Pro

I obtain the following exception when performing a conn.Open()
System.Net.Sockets.SocketException was unhandled 

The code is as follow:

conn = new MySqlConnection("SERVER=localhost;DATABASE=multiview;UID=root;PASSWORD=test;");
conn.Open(); // This is where it trows the exception.

This error ONLY occurs if the MySQL server is stopped. If the MySQL server is running, everything runs smoothly. 

It almost looks like this error is not being handled in the MySQL DLL.

How to repeat:
Execute the following code while the MySQL server is stopped:

conn = new MySqlConnection("SERVER=localhost;DATABASE=multiview;UID=root;PASSWORD=test;");
conn.Open(); // This is where it trows the exception.

Suggested fix:
Not sure but maybe having a try/catch on the connection attempt
[8 Aug 2006 10:48] Tonci Grgin
Hi Gerry and thanks for your problem report.
Connector/NET code:
SetState(ConnectionState.Connecting);
try 
  {
    if (settings.Pooling) 
      {
        driver = MySqlPoolManager.GetConnection(settings);
      }
    else
      {
        driver = Driver.Create(settings);
      }
  }
  catch (Exception)
    {
      SetState(ConnectionState.Closed);
      throw;
    }
As you can see, we are catching exception so that you know what's happening. Please use try...catch in your own code.