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

后端 未结 6 845
攒了一身酷
攒了一身酷 2021-02-13 02:06

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:33

    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.

提交回复
热议问题