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.