Question

We are testing some options to solve performance issues with .Net 4.0 SqlClient (lots of GC and finalizers, etc.) and were thinking of using a different Sql client implementation - Mono came to mind.

1) Is it possible to use the Mono implementation of SqlClient with a MS.Net application? if so- how?
2) Is the Mono implementation "stable"? which version is most recommended?
3) Does the mono implementation of SqlCommand, QueryResults, etc. contain finalizers?

Thanks!

Was it helpful?

Solution

If you are seeing these impact GC, then that suggests you aren't using them properly. Of these, SqlDataReader doesn't have a finalizer in the first place, so I assume we're talking about SqlCommand and SqlConnection. Both of these inherit from Component, and in both cases the Dispose() call unregisters them from GC - it is:

public void Dispose()
{
    this.Dispose(true);
    GC.SuppressFinalize(this);
}

So: if you are setting these appear as finalizers in GC, look to see whether you are disposing your objects correctly. The easiest way to do that is via using statements. For example:

using(var conn = OpenSomeConnection())
using(var cmd = conn.CreateCommand()) {
    // TODO configure command

    using(var reader = cmd.ExecuteReader()) {
        // TODO consume data
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top