The result code after conn.Open() is 0.

I can't check the result code after conn.Close() - that creates an invalid 
operation exception: "Database connection not valid for getting result code."

On the second pass, the conn.Open() result code is still 0. 

I tried checking resultCode in a couple different places but the only time it's 
valid is between the Open() and Close() commands. Since I'm not doing anything 
there, not much to report.

The Error (21) pops out immediately after stepping over the using statement the 
second time. 
-----Original Message-----
From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-boun...@sqlite.org] 
On Behalf Of Simon Slavin
Sent: Friday, February 03, 2012 10:40 AM
To: General Discussion of SQLite Database
Subject: Re: [sqlite] Error 21 on Open (C#)


On 3 Feb 2012, at 3:33pm, <phil_wha...@agilent.com> <phil_wha...@agilent.com> 
wrote:

> After distilling the problem down, I've found that this code will always 
> reproduce the error:
> 
> 
>        public Boolean TestConnection()
>        {
>            try
>            {
>                using (SQLiteConnection conn = new SQLiteConnection("Data 
> Source=agilent.db"))
>                {
>                    conn.Open();
> 
>                    Thread.Sleep(100);
> 
>                    conn.Close();
>                }
>            }
>            catch (Exception e)
>            {
>                return false;
>            }
>            return true;
>        }
> 
> The function will always return true, but the second time (and all future 
> times) you run it, the error (21) comes out on the console. Any operations on 
> the db will fail at that point.

Please check the result codes returned by conn.Open() and conn.Close() the 
first time through the loop.  Your 'try' is catching only operations which 
result in exceptions, not ones which result in non-zero result codes.

Simon.

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to