现在的位置: 首页 > 综合 > 正文

Error thrown by a dependency of object ‘System.Data.SQLite’ 解决办法

2013年02月17日 ⁄ 综合 ⁄ 共 3176字 ⁄ 字号 评论关闭

项目中用的.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;"/>

再运行,不报错了

抱歉!评论已关闭.