NHibernate on SQLite 3.0 – a workaround for “Could not find any resources appropriate for the specified culture or the neutral culture”

by acha11 29. June 2009 17:08

My iRacing stats tool, iStatistician, keeps its data store in a SQL Server Compact Edition database. I’m experimenting with SQLite using the SQLite ADO.NET 2.0 Provider as an alternative for use in a few small projects at work – it has a lighter deployment (one dll versus several), better performance, and (as far as I can tell; this is part of the test) presents no additional compatibility issues over SQL Server CE when used through an ORM.

I ran into a problem yesterday setting up NHibernate over SQLite 3.0:

System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture.  Make sure "System.Data.SQLite.SR.resources" was correctly embedded or linked into assembly "System.Data.SQLite" at compile time, or that all the satellite assemblies required are loadable and fully signed.
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
   at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
   at System.Data.SQLite.SR.get_Keywords()
   at System.Data.SQLite.SQLiteConnection.Schema_ReservedWords()
   at System.Data.SQLite.SQLiteConnection.GetSchema(String collectionName, String[] restrictionValues)
   at System.Data.SQLite.SQLiteConnection.GetSchema(String collectionName)
   at NHibernate.Dialect.Schema.AbstractDataBaseSchema.GetReservedWords() in c:\CSharp\NH\nhibernate\src\NHibernate\Dialect\Schema\AbstractDataBaseSchema.cs:lin
e 97
   at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect, IConnectionHelper connectionHelper) in c:\CSharp\NH\nhibernate\src\NHibernate\Tool\hbm2ddl\SchemaMetadataUpdater.cs:line 47
   at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory sessionFactory) in c:\CSharp\NH\nhibernate\src\NHibernate\Tool\hbm2ddl\SchemaMetadataUpdater.cs:line 17
   at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners) in c:\CSharp\NH\nhibernate\src\NHibernate\Impl\SessionFactoryImpl.cs:line 169
   at NHibernate.Cfg.Configuration.BuildSessionFactory() in c:\CSharp\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 1117

Reading the stack trace, it looks as though NHibernate is asking SQLite for a list of reserved words (by calling GetSchema(string)), and SQLite is trying to retrieve that list from the available embedded resource files/satellite assemblies and failing for some reason. SQLite certainly looks like it’s meant to support this kind of querying – its GetSchema() is calling into Schema_ReservedWords() and from there into its resource wrapper’s get_Keywords(), which is triggering the throw.

I haven’t solved the underlying problem, and googling hasn’t turned up anybody else with the same issue. This post is just to record the workaround i’m using in the very short term, which is to apply the NHibernate configuration setting “hbm2ddl.keywords” = “none”, which is telling NHibernate not to worry about retrieving the list of reserved words from the provider. I guess the impact of this setting is that NHibernate will not proactively escape column or table names that it knows will collide with SQLite’s reserved words, possibly leading to errors. This can be worked around – it’s possible to instruct NHibernate to escape a particular identifier in the mapping file on a column-by-column basis. So I’m going to plough ahead with the experiment and see what other issues I run into.

Tags:

Comments

Comments are closed

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

RecentComments

Comment RSS