項目中用的.net4+mvc3+spring.net1.3.2+nhibernate32+SQLite 1.0.79版本,就目前來說,應該是最新的,
在使用的時候單獨用nh連結sqlite是沒問題的,但是用spring.net配置nhibernate問題就來了,
1.3.2的版本就支援SQLite1.0.72的版本,因為我用的是1.0.79的版本,如果寫成System.Date.SQLite,報錯為
注意紅線的報錯,我查看了Spring.net的源碼,裡面是這樣寫的,
為什麼他會報這兒的錯呢,因為後面還有句:
<alias name="SQLite-1.0.65" alias="System.Data.SQLite"/>
他把這個直接映射到了1.0.65的版本,而且裡面最高的版本為1.0.72,沒有我想要的1.0.79,解決辦法很簡單,自己再加一個就是了,注意看我第一張圖:
<!--資料庫提供者--> <db:additionalProviders resource="assembly://Mark/Mark.ConfigFiles/SQLite.xml"/>
這個SQLite.xml就是我自己寫的,其實就是copy他的寫法,我只是不知道那個PublicKeyToken是多少,直接刪除了,一樣的可以用,SQLite.xml裡面的內容是:
<?xml version="1.0" encoding="utf-8" ?><objects xmlns="http://www.springframework.net" xmlns:db="http://www.springframework.net/database"> <object id="SQLite-1.0.79" type="Spring.Data.Common.DbProvider, Spring.Data" singleton="false"> <constructor-arg name="dbMetaData"> <object type="Spring.Data.Common.DbMetadata"> <constructor-arg name="productName" value="SQLite"/> <constructor-arg name="assemblyName" value="System.Data.SQLite, Version=1.0.79.0, Culture=neutral"/> <constructor-arg name="connectionType" value="System.Data.SQLite.SQLiteConnection, System.Data.SQLite, Version=1.0.79.0, Culture=neutral"/> <constructor-arg name="commandType" value="System.Data.SQLite.SQLiteCommand, System.Data.SQLite, Version=1.0.79.0, Culture=neutral"/> <constructor-arg name="parameterType" value="System.Data.SQLite.SQLiteParameter, System.Data.SQLite, Version=1.0.79.0, Culture=neutral"/> <constructor-arg name="dataAdapterType" value="System.Data.SQLite.SQLiteDataAdapter , System.Data.SQLite, Version=1.0.79.0, Culture=neutral"/> <constructor-arg name="commandBuilderType" value="System.Data.SQLite.SQLiteCommandBuilder, System.Data.SQLite, Version=1.0.79.0, Culture=neutral"/> <constructor-arg name="commandBuilderDeriveParametersMethod" value="not supported"/> <constructor-arg name="parameterDbType" value="System.Data.SQLite.TypeAffinity, System.Data.SQLite, Version=1.0.79.0, Culture=neutral"/> <constructor-arg name="parameterDbTypeProperty" value="DbType"/> <constructor-arg name="parameterIsNullableProperty" value="IsNullable"/> <constructor-arg name="parameterNamePrefix" value=":"/> <constructor-arg name="exceptionType" value="System.Data.SQLite.SQLiteException, System.Data.SQLite, Version=1.0.79.0, Culture=neutral"/> <constructor-arg name="useParameterNamePrefixInParameterCollection" value="true"/> <constructor-arg name="useParameterPrefixInSql" value="true"/> <constructor-arg name="bindByName" value="true"/> <!-- this is only true for .net 1.1 kept it here just in case we want to revert back to this strategy for obtaining error codes--> <constructor-arg name="errorCodeExceptionExpression" value="ErrorCode.ToString('D')"/> <property name="ErrorCodes.badSqlGrammarCodes"> <value></value> </property> <property name="ErrorCodes.DataAccessResourceFailureCodes"> <value>1</value> </property> <property name="ErrorCodes.DataIntegrityViolationCodes"> <value></value> </property> <property name="ErrorCodes.CannotAcquireLockCodes"> <value>15</value> </property> <property name="ErrorCodes.DeadlockLoserCodes"> <value>5,6</value> </property> </object> </constructor-arg> </object></objects>
然後寫:
<db:provider id="DbProvider" provider="SQLite-1.0.79" connectionString="Data Source=|DataDirectory|xxxx.db;Version=3;FailIfMissing=False;"/>
再運行,不報錯了