.net SqlConnection not being closed even when within a using { }

后端 未结 6 1295

Please help!

Background info

I have a WPF application which accesses a SQL Server 2005 database. The database is running locally on the machine the appl

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-13 02:22

    I think the connection, while no longer referenced, is waiting for the GC to dispose of it fully.

    Solution:

    Create your own DataContext class which derives from the auto-generated one. (rename the base one so you don't have to change any other code).

    In your derived DataContext - add a Dispose() function. In that - dispose the inner connection.

提交回复
热议问题