我在項目中用微軟企業庫的方式連接SqlServer Ce不成功,但是連接MSSQL沒問題;
我想知道微軟企業庫是否能連接SqlServer Ce;
配置文件
<add name="CS_Telecom" connectionString="Data Source=D:\EWS_Project\DataBase\MyDatabase#1.sdf;Password=123456" providerName="Microsoft.SqlServerCe.Client"/>
代碼
public virtual void CreateDatabase()
{
if (string.IsNullOrEmpty(DBName))
{
this.db = Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.CreateDatabase();
}
else
{
this.db = Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.CreateDatabase(DBName);
}
}
錯誤信息
Activation error occured while trying to get instance of type Database, key "CS_Telecom"
把配置文件改成,就解決了
<add name="CS_Telecom" connectionString="Data Source=D:\EWS_Project\DataBase\MyDatabase#1.sdf;Password=123456" providerName="System.Data.SqlServerCe.3.5"/>