in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

IIS handle leak using managed dll

Last post 08-02-2010 6:00 AM by satis. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 07-30-2010 8:39 AM

    • satis
    • Not Ranked
    • Joined on 07-30-2010
    • Posts 3

    IIS handle leak using managed dll

     I've run into an unfortunate problem doing some simple stuff with the managed dll.  The problem does not occur with the mixed code dll, but unfortunately I have to be able to run this on Win2008, which I wasn't able to do using the mixed code version.

     I simplified the code down to this, which causes the handle leak.

    using System.Data.SQLite;

    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SQLiteConnection conn = new SQLiteConnection("Data Source=c:\\test.db");
            conn.Open();
            SQLiteCommand cmd = new SQLiteCommand("select * from updates", conn);
            SQLiteDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            dr.Dispose();
            cmd.Dispose();
            conn.Close();
        }
    }

     Using the managed dll (v.1.0.66.0) and sqlite3.dll (3.6.23.1), every time the page is refreshed, w3wp.exe leaks another handle to c:\test.db.  I've duplicated the issue on win2003x32 and win2008x64.  I tried recycling the app pool to see if that would clear it, but that unfortunately didn't work.  The only way to clear it is to restart IIS.

    Any ideas on how to work around this?  I'm not averse to using the mixed code dll if I can get it running under win2008.  I found some mentions of having to switch IIS to full trust to get that to work, but was unable to get that working.  I'm also a bit unsure about altering machine.config files, since this will be residing on servers owned by others and residing in their data centers.

  • 07-30-2010 1:58 PM In reply to

    • iMP
    • Top 500 Contributor
    • Joined on 01-13-2008
    • Posts 6

    Re: IIS handle leak using managed dll

    Not sure if it helps, I would try adding conn.Dispose();

     or

    using (SQLiteConnection conn = xxx)

    {

    }

     

     

  • 08-02-2010 5:39 AM In reply to

    • satis
    • Not Ranked
    • Joined on 07-30-2010
    • Posts 3

    Re: IIS handle leak using managed dll

     Thanks for the suggestions, iMP.  Unfortuantely, I'm still running into the same problem.  I tried wrapping everything I could into using statements, but continue to get a handle leaked every page refresh.  I also tried explicitly disposing of the connection object with no success.

    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            using(SQLiteConnection conn = new SQLiteConnection("Data Source=c:\\test.db")){
                conn.Open();
                using(SQLiteCommand cmd = new SQLiteCommand("select * from updates", conn)){
                    using(SQLiteDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)){
                        //stuff
                    }
                }
            }
        }
    }

    Interestingly enough, if I comment out the ExecuteReader using statement, I don't leak anything, so it would seem the problem isn't in the connection itself.

     I'm open to any further suggestions or ideas if anyone has any.

  • 08-02-2010 6:00 AM In reply to

    • satis
    • Not Ranked
    • Joined on 07-30-2010
    • Posts 3

    Re: IIS handle leak using managed dll

     I apologize for the double post.  However, I was able to get this working using the 64-bit mixed-code dll.  I need to test this on a clean win2008 box to verify some other part of my messing with this didn't fix it, but ultimately I just did the following:

    1. put the 64-bit mixed code dll into the bin folder
    2. set the specific IIS web application to full trust using the .net trust levels widget in IIS Manager

    It's also possible to use the 32 bit dll.  In addition to the two steps above, you have to go into the application pool advanced settings for the web app and set the 'Enable 32-bit applications' boolean.  If enabled, you have to use the 32 bit DLL, is disabled the 64 bit.  Trying to mix that will result in a BadImageFormatException.

    I'm still curious what the issue is using the managed-only DLL. but at this point it's more out of curiosity than because I need it fixed.

Page 1 of 1 (4 items)
Powered by Community Server (Commercial Edition), by Telligent Systems