Hi Joe,

We are not using multiple app domains within a process. 

Within the process where the errors are coming from we have

* N databases being accessed, typically between 5-100 separate databases
* Each database has a dedicated handler, to ensure we only ever invoke 1 writer 
at a time to a database.
* All communication to the database is going through the SQLite C# code, 
connections always via the SQLiteConnection instance.

The code follows the form of

Using(var connection = connectionFactory.CreateConnection())
{
    Connection.Open();
   // do something useful in here.
}

There is 1 connection factory per database. The create connection call above 
does the following

       /// <inheritdoc />
        public IDbConnection CreateConnection()
        {
            EnsureExists(); // Create the file if not there.

            return new 
SQLiteConnection(ConnectionStringBuilder.ConnectionString, true);
        }

      [NotNull]
        private DbConnectionStringBuilder ConnectionStringBuilder
        {
            get
            {
                var builder = new SQLiteConnectionStringBuilder
                {
                    DataSource = m_Factory.DatabasePath(),
                    Version = 3,
                    DefaultTimeout = 60,
                    PageSize = m_ConnectionOptions.PageSize,
                    JournalMode = SQLiteJournalModeEnum.Persist,
                    BinaryGUID = true,
                    FailIfMissing = true,
                    SyncMode = m_ConnectionOptions.SynchronizationMode,
                    Pooling = m_ConnectionOptions.UseConnectionPool,
                };

                return builder;
            }
        }

Typically connection pooling will be on.

At application start, each of the database handlers will verify once that the 
table schema in the database is ok. In order to do that they first open a 
connection as per above, that is when the exception tends to occur. The 
application internally is multi-threaded, each of the database handlers will 
execute concurrently (they are scheduled onto the thread pool), so many 
connection objects will get instantiated very close to each other time wise.

Unfortunately the problem seems to be very difficult to replicate reliably. 
Generally we are seeing around about a 5% failure rate at application start. 
Any further info, ask away.

Hope that helps,
Barry Roberts. 

Message: 7
Date: Tue, 14 May 2019 16:34:16 -0400
From: "Joe Mistachkin" <j...@mistachkin.com>
To: "'General Discussion of SQLite Database'"
        <sqlite-users@mailinglists.sqlite.org>
Subject: Re: [sqlite] Odd exception when creating a connection object
Message-ID: <3EA5A76974A44B60A3EC32B67C8C6D5A@LACHRYMOSE>
Content-Type: text/plain;       charset="us-ascii"


Barry Roberts wrote:
> 
> InvalidOperationException: code = Misuse (21), message = 
> System.Data.SQLite.SQLiteException (0x800007EF): bad parameter or other
API 
> misuse
> 

Are you using multiple AppDomains?  Do you have other threads in the process
accessing SQLite via its native API while the connections are being created?

Any details you could provide in order to reproduce this could be useful.

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

Reply via email to