我正在接受
每当我将默认数据库引用到SQL Server CE 时,我的“尝试获取类型实例时发生激活错误 数据库,键“”“
DatabaseFactory.CreateDatabase()
会出现异常
我尝试检查问题是否只是我的.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”
答案 0 :(得分: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>