locked
NullReferenceException RRS feed

  • Question

  • Hi, guys!

    I've a project which working with databases via MySqlConnector.

    The project was written, compiled and sent to user one year ago.

    Now I want to make some changes in this project. But I can't running my old code.

    Everytime I trying to start project in IDE I receive an error message: NullReferenceException not handled.

    I not made any changes in the code, but now code not working. What this means?

    Here is a code:

     

      Private Sub btnConnect_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnConnect.Click
        Dim err As New MySqlErrorCode
    
        gConn = New MySqlConnection("server=" + txtIP.Text + ";user id=root;password=;database=test;CharSet=cp1251;")
        gCmd = New MySqlCommand
        Try
          gConn.Open()

    At the gConn.Open I recieving NullReferenceException.

    .NET Framework wasn't reinstalled or reconfigured. Also MySqlConnector wasn't changed.

    What happens since last year???

     

    Thanks in advance!

    Friday, February 25, 2011 11:17 AM

Answers

  • I don't and probably nobody here knows what happened at your place, maybe somebody changed an IP address or whatever.

    However, try to avoid the + to concatenate strings in VB use the string concatination character &

    (And put on top of your page Option Strict On)


    Success
    Cor
    • Marked as answer by Hazrit Friday, February 25, 2011 2:44 PM
    Friday, February 25, 2011 1:13 PM

All replies

  • You didn't say which line specifically has the null reference exception.  Can you set a breakpoint and step through these lines?  This would allow you to inspect each object and see what exactly is null.  For instance, is it gconn that is null after instantiation or is the exception occurring within the call stack of the connection instantiation?  This could be a big difference since the former suggests contextual values have changes versus the latter suggesting that the MySqlCOnnector itsdelf is having issues.

    Also, have you read the documentation on the MySqlConnector classes and methods?  Sometimes documentation will tell you that a particular exception is thrown for specific reasons.

    Friday, February 25, 2011 1:11 PM
  • I don't and probably nobody here knows what happened at your place, maybe somebody changed an IP address or whatever.

    However, try to avoid the + to concatenate strings in VB use the string concatination character &

    (And put on top of your page Option Strict On)


    Success
    Cor
    • Marked as answer by Hazrit Friday, February 25, 2011 2:44 PM
    Friday, February 25, 2011 1:13 PM
  • Thanks for the replies!

    gConn variable isn't Nothing, but mysql accessibility was resetted in unknown reasons. May be ip changing is a reason. Old ip was 192.168.1.77 currently is 192.168.1.2.

    The problem was fixed with mysql command

    GRANT ALL PRIVILEGES ON *.* TO root@`%` WITH GRANT OPTION;


    No more problems.

    Thanks!

    Friday, February 25, 2011 2:44 PM