문제

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!

도움이 되었습니까?

해결책

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
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top