• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 473
  • Last Modified:

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
0
Dan560
Asked:
Dan560
  • 9
  • 8
1 Solution
 
käµfm³d 👽Commented:
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

0
 
Dan560Author Commented:
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
0
 
käµfm³d 👽Commented:
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"?
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
Dan560Author Commented:
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.
0
 
käµfm³d 👽Commented:
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.
0
 
käµfm³d 👽Commented:
How many parameters is the Convert.ToString call taking?
0
 
Dan560Author Commented:
I have counted the convert.tostring and there are 28 references to it.
0
 
Dan560Author Commented:
Would it help if I pasted the code?
0
 
käµfm³d 👽Commented:
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.
0
 
Dan560Author Commented:
no problem
code.txt
0
 
käµfm³d 👽Commented:
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?
0
 
käµfm³d 👽Commented:
Also, which version of the MySql connector are you using?
0
 
Dan560Author Commented:
4.0.16
connector = 5.1.0.0

Thanks.
0
 
käµfm³d 👽Commented:
At this point, I can only agree with your suggestion about trying a different version of the connector; however, you won't be able to go up, rather you will need to go down. According to this chart, you are using the highest version that still supports MySQL 4.0. You might try v5.0 of the connector; v1.0 if v5.0 doesn't work. I am not 100% on this, but I don't know what else to try. It seems the server is passing back a bogus version number, which the internal code cannot convert to an integer.
0
 
Dan560Author Commented:
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!
0
 
käµfm³d 👽Commented:
Sure thing. Glad to help  = )
0
 
Dan560Author Commented:
Thank you for your fantastic support. I had the provider change it back to 4.0.16... my script works fine now :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 9
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now