1

我得到一个

“尝试获取类型数据库实例时发生激活错误,密钥“”“

DatabaseFactory.CreateDatabase()每当我将默认数据库引用到 SQL Server CE 时,我的例外

我尝试检查问题是否只是我的 .dll 引用,我能够证明这是错误的,因为我仍然能够连接到真正的 SQL Server 2008 数据库。

这是我的配置:

<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false"/>
    </configSections>
<dataConfiguration defaultDatabase="sqlCEDB"/>
    <connectionStrings>
        <add name="sqlCEDB"
           connectionString="Data Source=|DataDirectory|\sqlCEDB.sdf;Password='somepassword'"
           providerName="Microsoft.SqlServerCe.Client.3.5" />
</connectionStrings>

这是我创建数据库实例的方法:

private Database db;

protected internal Database DB
{
   get 
   {
      if (db == null)
         db = DatabaseFactory.CreateDatabase();
      return db; 
   }
}

解决方案

更改配置属性已解决:providerName="System.Data.SqlServerCe.3.5"

4

1 回答 1

2

解决方案

更改配置属性已解决:providerName="System.Data.SqlServerCe.3.5"

<configSections>
    <section name="dataConfiguration" 
             type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
             requirePermission="false"/>
</configSections>
<dataConfiguration defaultDatabase="sqlCEDB"/>
    <connectionStrings>
        <add name="sqlCEDB"
             connectionString="Data Source=|DataDirectory|\sqlCEDB.sdf;Password='somepassword'"
             providerName="System.Data.SqlServerCe.3.5" />
    </connectionStrings>
于 2012-02-29T06:02:47.593 回答