Link to home
Start Free TrialLog in
Avatar of Dan560
Dan560Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Unhandled Exception: System.FormatException: Input string was not in a correct format.

Hi,

A former colleague of mine wrote a VB application that imports data into a MYSQL server.

The script has worked fine for a good number of years. However the MYSQL server was recently upgraded to version 4.0.16 (old I know) and now my script does not work.

Our server is managed by our hosting provider and unfortunately I do not have any management access.

The error message I get when running the script is -

Connecting to MySQL...
server=83.x.x.x;user=userhere;database=swdata;port=5002;password=passwordhere

Unhandled Exception: System.FormatException: Input string was not in a correct f
ormat.
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffe
r& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo in
fo)
   at MySql.Data.Common.DBVersion.Parse(String versionString)
   at MySql.Data.MySqlClient.NativeDriver.Open()
   at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.GetConnection()
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at Daily_Report.Daily_Report.Main() in C:\Users\scripts\daily\Module1.vb:line 69

Line 69 shows - DBconnection1.Open()

Can anyone help me with this issue? I am afraid to say I have no VB writing knowledge and would really appreciate some help.

Thank you
Avatar of kaufmed
kaufmed
Flag of United States of America image

Somewhere in the code you are trying to call one of the methods of the Convert class, and the method being called is being passed an incompatible value.

e.g.

Dim x As Integer = Convert.ToInt32("hello world")

Open in new window

Avatar of Dan560

ASKER

Hi kaufmed,

I have to admit my VB.net knowledge is limited. I found this at the begging of the code.

Does this help with troubleshooting the issue? Please let me know if more code is needed?

 Sub Main()

        ' ########################################################
        ' #              Create Database Connections             #
        ' ########################################################


        Dim DBconnectString As String

        Dim DBconnection1 As New MySqlConnection
        Dim DBsqlstatement1 As String
        Dim DBsqlcommand1 As New MySqlCommand
        Dim DBsqlreader1 As MySqlDataReader

        Dim DBconnection2 As New MySqlConnection
        Dim DBsqlstatement2 As String
        Dim DBsqlcommand2 As New MySqlCommand
        Dim DBsqlreader2 As MySqlDataReader

        Dim DBconnection3 As New MySqlConnection
        Dim DBsqlstatement3 As String
        Dim DBsqlcommand3 As New MySqlCommand
        Dim DBsqlreader3 As MySqlDataReader
Those are just variable declarations. They only say what you are going to use, not how how you are going to use them.

In any event, I'm not entirely sure how the process of connecting to MySql itself would cause that error. As I mentioned above, that message is typically because of an invalid conversion. Do you see any mention of "Convert.ToXXXX"?
Avatar of Dan560

ASKER

Yes however nothing that references the connection to the MYSQL.

I did a search for Convert.To , and found the following code mentioned

"Convert.ToString"

Do you think I might need to upgrade the mysql. net connector to the latest version? It's just a thought.
I did a search for Convert.To , and found the following code mentioned

"Convert.ToString"
I don't think that method can even throw an exception. The reason I believe so is that everything in .NET has a ToString method, which is what gets called when you execute that function. Do you see any other Convert lines?

Do you think I might need to upgrade the mysql. net connector to the latest version?
I don't immediately see why, but I suppose you could try it.
How many parameters is the Convert.ToString call taking?
Avatar of Dan560

ASKER

I have counted the convert.tostring and there are 28 references to it.
Avatar of Dan560

ASKER

Would it help if I pasted the code?
I figured you didn't want to because it was sensitive, but yes, it would  = )

You can change any sensitive details as you see fit.
Avatar of Dan560

ASKER

no problem
code.txt
OK, I concur that you don't have any calls to Convert.ToXXX other than the ToString calls. It also seems I didn't read your error close enough. What version of MySQL are you running?
Also, which version of the MySql connector are you using?
Avatar of Dan560

ASKER

4.0.16
connector = 5.1.0.0

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dan560

ASKER

Hi,

I think you have hit the nail on the head..

I have ran a query to show the server version and it comes back with a bogus (custom) value.

I have asked my hosting provider to update the version value.

I will post back tomorrow with an update. Thanks for the support today!
Sure thing. Glad to help  = )
Avatar of Dan560

ASKER

Thank you for your fantastic support. I had the provider change it back to 4.0.16... my script works fine now :)