Re: [sqlite] Handle leak using IIS on windows 7?
This was exactly the problem; I didn't realize the 'static' variables are persisted between page views in ASP.Net Adding an '_instance = null;' fixed the issue. Thanks muchly. Cheers, Doug. On Tue, Jul 19, 2011 at 11:58 AM, Joe Mistachkinwrote: > > After reading the code, I noticed the following: > > 1. From the static Dump method, an instance of the DbLogger class is > created via the static Get method and stored in the _instance static > variable. > > 2. The connection itself is opened in the constructor for the DbLogger > class via the InitDb method. > > 3. Prior to returning a result, the Dump method closes the connection > and sets the _connection instance variable to null. > > 4. The second time the Dump method is executed, the existing instance > of the DbLogger class will be used (i.e. the one stored in the static > _instance variable). > > 5. This existing instance of the DbLogger class no longer has a valid > connection because it was previously closed (and set to null). > > 6. Newly created commands will not have a valid connection. > > 7. Attempting to execute a command without a valid connection will > result in the exception you are seeing. > > -- > Joe Mistachkin > > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Handle leak using IIS on windows 7?
After reading the code, I noticed the following: 1. From the static Dump method, an instance of the DbLogger class is created via the static Get method and stored in the _instance static variable. 2. The connection itself is opened in the constructor for the DbLogger class via the InitDb method. 3. Prior to returning a result, the Dump method closes the connection and sets the _connection instance variable to null. 4. The second time the Dump method is executed, the existing instance of the DbLogger class will be used (i.e. the one stored in the static _instance variable). 5. This existing instance of the DbLogger class no longer has a valid connection because it was previously closed (and set to null). 6. Newly created commands will not have a valid connection. 7. Attempting to execute a command without a valid connection will result in the exception you are seeing. -- Joe Mistachkin ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Handle leak using IIS on windows 7?
On 19 Jul 2011, at 4:07am, Doug wrote: > I'm pretty sure the issue is something to do with file handles. For the same > reason after loading the page (from an IIS server) and then closing the > page, waiting 1 minute or two and then attempting to remove the db.sqlite > file, I get an "error, file is in use". Remove as much as you can and see if the error disappears. For instance, delete the stuff about creating and deleting the file. Delete the stuff about creating the table. In fact everything that depends on 'init'. What about that INSERT ? If you remove it does the error go away ? Give us a ten-line toy example that still produces the error. Then we'll be more likely to guess what's going on. Simon. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Handle leak using IIS on windows 7?
ection); sqlCmd.CommandText = cmd; SQLiteDataReader reader = sqlCmd.ExecuteReader(); while(reader.Read()) { var instance = new DbLoggerRecord(); int i = reader.GetOrdinal("Created"); String createdString = (string) reader.GetValue(i); instance.Created = (DateTime) DateTime.Parse(createdString); if (reader.GetValue(reader.GetOrdinal("Context")).GetType() != typeof(DBNull)) instance.Context = (String)reader.GetValue(reader.GetOrdinal("Context")); else instance.Context = "NULL"; if (reader.GetValue(reader.GetOrdinal("Message")).GetType() != typeof(DBNull)) instance.Message = (String) reader.GetValue(reader.GetOrdinal("Message")); else instance.Message = "NULL"; rtn.Add(instance); } return rtn; } public void Clear() { string cmd = "DELETE FROM Log"; var sqlCmd = new SQLiteCommand(_connection); sqlCmd.CommandText = cmd; sqlCmd.ExecuteNonQuery(); } public void Commit() { if (_transaction != null) { _transaction.Commit(); _transaction = null; } } public string HtmlFormatRecords(IEnumerable records) { StringBuilder b = new StringBuilder(); b.Append("DbLogger"); foreach(DbLoggerRecord record in records) { b.Append(String.Format("{0}: {1}", record.Context, record.Message)); } b.Append(""); return b.ToString(); } public static DbLogger Get() { if (_instance == null) _instance = new DbLogger(); return _instance; } public static string Dump() { var l = Get(); var rtn = l.HtmlFormatRecords(l.GetRecords(100)); l.Close(); // If we're printing, we're done for now. return (rtn); } } } On Mon, Jul 18, 2011 at 8:09 PM, Black, Michael (IS) <michael.bla...@ngc.com > wrote: > If you showed a small sample code that caused your problem it would sure > help a lot. > > > > I peeked at the library code. That message is generated when _cnn is null > (the DB connection). > >private void InitializeForReader() >{ > if (_activeReader != null && _activeReader.IsAlive) >throw new InvalidOperationException("DataReader already active on > this command"); > > if (_cnn == null) >throw new InvalidOperationException("No connection associated with > this command"); > > > > It is set on a "new Connection". > > > > It is only turned to null in one place (in Commit). But why in the world > you would null _cnn on a commit is beyond me. > > Are you using a commit? It could be autocommit I supposed causing it. > > I'd comment out that "_cnn = null" line below and see if it solves your > problem. Sure would explain why it only works once. > > > > /// >/// Commits the current transaction. >/// >public override void Commit() >{ > IsValid(true); > > if (_cnn._transactionLevel - 1 == 0) > { >using (SQLiteCommand cmd = _cnn.CreateCommand()) >{ > cmd.CommandText = "COMMIT"; > cmd.ExecuteNonQuery(); > } > } > _cnn._transactionLevel--; > _cnn = null; >} > > > > Michael D. Black > > Senior Scientist > > NG Information Systems > > Advanced Analytics Directorate > > > > > From: sqlite-users-boun...@sqlite.org [sqlite-users-boun...@sqlite.org] on > behalf of Doug [douglas.lin...@gmail.com] > Sent: Monday, July 18, 2011 1:34 AM > To: sqlite-users@sqlite.org > Subject: EXT :[sqlite] Handle leak using IIS on windows 7? > > Hi there, > > I've searched around and found a few threads like this: > http://sqlite.phxsoftware.com/forums/t/2480.aspx > > Basically, I have the same issue. > > When access the sqlite database via a website (MVC3 running on IIS) the > first time, sqlite works fine. > > I properly call connections.Close() when I'm done... > > And the next time I try to access it I get: > System.InvalidOperationException: No connection associated with this > command > > Manually stopping the dev web server, or restarting the iis application
Re: [sqlite] Handle leak using IIS on windows 7?
If you showed a small sample code that caused your problem it would sure help a lot. I peeked at the library code. That message is generated when _cnn is null (the DB connection). private void InitializeForReader() { if (_activeReader != null && _activeReader.IsAlive) throw new InvalidOperationException("DataReader already active on this command"); if (_cnn == null) throw new InvalidOperationException("No connection associated with this command"); It is set on a "new Connection". It is only turned to null in one place (in Commit). But why in the world you would null _cnn on a commit is beyond me. Are you using a commit? It could be autocommit I supposed causing it. I'd comment out that "_cnn = null" line below and see if it solves your problem. Sure would explain why it only works once. /// /// Commits the current transaction. /// public override void Commit() { IsValid(true); if (_cnn._transactionLevel - 1 == 0) { using (SQLiteCommand cmd = _cnn.CreateCommand()) { cmd.CommandText = "COMMIT"; cmd.ExecuteNonQuery(); } } _cnn._transactionLevel--; _cnn = null; } Michael D. Black Senior Scientist NG Information Systems Advanced Analytics Directorate From: sqlite-users-boun...@sqlite.org [sqlite-users-boun...@sqlite.org] on behalf of Doug [douglas.lin...@gmail.com] Sent: Monday, July 18, 2011 1:34 AM To: sqlite-users@sqlite.org Subject: EXT :[sqlite] Handle leak using IIS on windows 7? Hi there, I've searched around and found a few threads like this: http://sqlite.phxsoftware.com/forums/t/2480.aspx Basically, I have the same issue. When access the sqlite database via a website (MVC3 running on IIS) the first time, sqlite works fine. I properly call connections.Close() when I'm done... And the next time I try to access it I get: System.InvalidOperationException: No connection associated with this command Manually stopping the dev web server, or restarting the iis application pool fixes this for one more page view. It seems like the IIS config is leaving the process hanging around, and after calling close there (I guess) must be some handle which is being kept and keeping a reference to the database, preventing anything else from accessing it. Seeing as how this has happened to a few people, I was hoping someone here had seen this before and had a solution? I'm using the Precompiled Binaries for 32-bit Windows (.NET Framework 4.0) from http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki(32 bit mode enabled on iis), but I've tried the 64-bit version with the same result. Cheers, Doug. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] Handle leak using IIS on windows 7?
Hi there, I've searched around and found a few threads like this: http://sqlite.phxsoftware.com/forums/t/2480.aspx Basically, I have the same issue. When access the sqlite database via a website (MVC3 running on IIS) the first time, sqlite works fine. I properly call connections.Close() when I'm done... And the next time I try to access it I get: System.InvalidOperationException: No connection associated with this command Manually stopping the dev web server, or restarting the iis application pool fixes this for one more page view. It seems like the IIS config is leaving the process hanging around, and after calling close there (I guess) must be some handle which is being kept and keeping a reference to the database, preventing anything else from accessing it. Seeing as how this has happened to a few people, I was hoping someone here had seen this before and had a solution? I'm using the Precompiled Binaries for 32-bit Windows (.NET Framework 4.0) from http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki(32 bit mode enabled on iis), but I've tried the 64-bit version with the same result. Cheers, Doug. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users