tags:

views:

60

answers:

1

In trying to write a simple C# ADO.NET application to connect to my database and manage project entries for my website, I've run into a strange problem that I can not find any information regarding. I've verified that my MySQL server is accepting remote connections, listening on port 3306, the username provided is valid, as is the password, and the hostname resolves correctly. However, when SqlConnection.Open is called, I receive a nonsensical exception.

System.ArgumentOutOfRangeException was unhandled

Non-negative number required.

Parameter name: count

Below is the code that invokes said error, specifically on the call to m_ActiveConnection.Open()

static public void OpenConnection(CConnectionDescription ConnectionDescription)
{
    try
    {
        SqlConnectionStringBuilder ConnectionStringBuilder = new SqlConnectionStringBuilder();
        ConnectionStringBuilder.DataSource = ConnectionDescription.Address + "," + ConnectionDescription.PortNumber;
        ConnectionStringBuilder.UserID = ConnectionDescription.UserName;
        ConnectionStringBuilder.Password = ConnectionDescription.Password;
        ConnectionStringBuilder.NetworkLibrary = "DBMSSOCN";

        if (m_ActiveConnection != null)
        {
            if (m_ActiveConnection.State != System.Data.ConnectionState.Closed)
            {
                m_ActiveConnection.Close();
            }
            m_ActiveConnection.ConnectionString = ConnectionStringBuilder.ConnectionString;
        }
        else
        {
            m_ActiveConnection = new SqlConnection(ConnectionStringBuilder.ConnectionString);
        }
        m_ActiveConnection.Open();
        m_ActiveConnectionDescription = ConnectionDescription;

        if (ConnectionChanged != null)
        {
            ConnectionChanged();
        }
    }
    finally
    {
        // Error message
    }
}

What can cause this exception? I'm not passing any parameters to open and the ConnectionString seems completely valid. I've checked the values of the CConnectionDescription my self. Any help would be appreciated.

+3  A: 

As far as I know, SqlConnection is used to connect to SqlServer databases. You should be using MySqlConnection from "MySQL Connector/Net".

Guilherme Oenning
I should have expected that, but I'd hoped that they'd specify MSSQL if that was the case. I'll switch to using the MySQL Connector/Net then. Much appreciated sir.
Sion Sheevok