English 中文(简体)
MySQL.Data: "Object reference not set to an instance of an object" when trying to Connect
原标题:

I have a "Cron Service" that i ve had running on our production server for over a year and a half.

It s a regular windows service which every minute connects to the DB, checks on one table whether there s something to do, and if so, does it. This is a server for a website that s not used a lot, so most of the time the service is completely idle.

A couple months ago, this service started throwing the following exception and dying:

MESSAGE: Object reference not set to an instance of an object.
SOURCE: MySql.Data
TARGETSITE: MySql.Data.MySqlClient.Driver CheckoutConnection()
STACKTRACE:    at MySql.Data.MySqlClient.MySqlPool.CheckoutConnection()
   at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
   at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
   at MySql.Data.MySqlClient.MySqlPool.GetConnection()
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   at DBA.Connect() in D:xxxDBA.vb:line 21
   at CronService.TaskMailings.OnExecute() in D:xxxTaskMailings.vb:line 54
   at CronService.CronTask.ThreadExecute() in D:xxxCronTask.vb:line 99
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

The exception is clearly coming from inside the MySQL Library. Also, my function that calls it is pretty simple:

    Public Shared Function Connect() As MySqlConnection
        Dim strConnString As String = WebConfigurationManager.AppSettings("ConnectionString")
        Dim DBConn As New MySqlConnection(strConnString)
        DBConn.Open()
        Return DBConn
    End Function

And the function where I m calling DBA.Connect() (CronService.TaskMailings.OnExecute) is doing so with a "Using" statement, so the connection is getting closed, this shouldn t be a problem of connections being left open and getting exhausted (although it might, if there s a bug inside the MySQL library).

This is the connection string I m using for the Service:

 server=localhost;port=13306;uid=xxx;pwd=xxx;database=xxx;Pooling=True;charset=utf8;

Any ideas what might be going on here? The strangest part is that this has worked for well over a year before it started happening out of the blue, and load to the server hasn t changed enough to justify it being a load problem, I believe.


EDIT: Some of the times it dies, it gives this other error message:

MESSAGE: error connecting: Timeout expired.  The timeout period elapsed prior to obtaining a connection from the pool.  This may have occurred because all pooled connections were in use and max pool size was reached.
SOURCE: MySql.Data
TARGETSITE: MySql.Data.MySqlClient.Driver GetConnection()
STACKTRACE:    at MySql.Data.MySqlClient.MySqlPool.GetConnection()
   at MySql.Data.MySqlClient.MySqlConnection.Open()
   atDBA.Connect() in D:xxxDBA.vb:line 21

Although the error message is pretty clear, like I mentioned before, we are releasing all connections, so this shouldn t happen. Any ideas?

问题回答

I realize this is an old question however the issue lies in the mysql.data.dll

What version was this tested against?

I m currently seeing this issue in 5.2.2.0 (and it doesn t happen in 5.0.1.0).

I d suggest either down grading to 5.0.1.0 or upgrading to the latest and seeing if it still occurs.





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签