in

System.Data.SQLite

An open-source, enhanced version of the SQLite database engine for Windows

SqliteConnectionStringBuilder not threadsafe

Last post 12-18-2007 8:57 AM by jpwkeeper. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 12-18-2007 8:57 AM

    SqliteConnectionStringBuilder not threadsafe

    Please note:  This is Microsoft bug, not a bug in System.Data.Sqlite.  I have submitted this bug to Microsoft, but thought it prudent to submit it here as well.

     SliteConnectionStringBuilder inherits from DbConnectionStringBuilder, which (eventually) uses ReflectTypeDescriptionProvider.ReflectGetProperties which accesses a static hashtable, _propertyCache, without a lock.  If you are building connection strings in many threads, there is a very rare exception that will sometimes occur:

      System.IndexOutOfRangeException: Index was outside the bounds of the array.
       at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
       at System.Collections.Hashtable.set_Item(Object key, Object value)
       at System.ComponentModel.ReflectTypeDescriptionProvider.ReflectGetProperties(Type type)
       at System.ComponentModel.ReflectTypeDescriptionProvider.ReflectedTypeData.GetProperties()
       at System.ComponentModel.TypeDescriptor.TypeDescriptionNode.DefaultTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetProperties()
       at System.ComponentModel.TypeDescriptor.GetPropertiesImpl(Object component, Attribute[ attributes, Boolean noCustomTypeDesc, Boolean noAttributes)
       at System.ComponentModel.TypeDescriptor.GetProperties(Object component, Boolean noCustomTypeDesc)
       at System.Data.Common.DbConnectionStringBuilder.GetProperties(Hashtable propertyDescriptors)
       at System.Data.SQLite.SQLiteConnectionStringBuilder.Initialize(String cnnString)
       at System.Data.SQLite.SQLiteConnectionStringBuilder..ctor()

    Caused by this Microsoft bug.  Although it is rare, if you are accessing many databases from many threads in an app, you should probably put a lock of a static object around your construction of the connection builder.  It should ONLY happen during construction. 

    Filed under:
Page 1 of 1 (1 items)
Powered by Community Server (Commercial Edition), by Telligent Systems