C # MySQL connection problems

I am trying to connect a C # application (using Visual C # 2008 Express Edition) to a remote MySQL server. I have drivers for this, but when I followed the tutorials (including adding union and connection reset properties) I get the error: Object reference not set to object instance. I have included two lines of code that should establish the connection. The error is displayed on the second line.

        MySqlConnection connect = new MySqlConnection("database=d*******;Data Source=mysql.netfirms.com;user id=*******;pwd=*****;pooling=false;connection reset=false");
        connect.Open();

      

+1


source to share


3 answers


I would try to set the connection string outside of the constructor to reduce the problem:

MySqlConnection connect = new MySqlConnection();
//Do you get the null exception in this next line?
connect.ConnectionString = "your conn string here";
connect.Open(); //-> If you get the exception here then the problem is with the connection string and not the MySqlConnection constructor.

      



If you get an exception on connect.ConnectionString = ... then the problem is with the driver and sounds like you need to reinstall it.

I would also try a simpler connection string without the merge and reset commands.

+2


source


Can you post more code? The exception line is probably a little off track due to or related to compiler optimizations. Constructors must return an object or throw an exception. It is impossible to tell

MyType item = new MyType();
Debug.Fail(item == null); // will never fail.

      



The null reference is probably on the line just above your instance.

+1


source


Could it be related to this error?

0


source







All Articles