I have trouble connecting the SqlCe database from DAAB, I can connect to it the usual way, via creating a SqlCeConnection, etc. I've setup the custome provider in the App.Config file according to the help file with the connection string pointing to my
SqlCe database file. My code is:
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand("select * from table1");
DataSet ds = new DataSet();
db.LoadDataSet(cmd, ds, "table1");
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = ds.Tables0;
and it will give me an error of "Could not load file or assembly Microsoft.Practices.EnterpriseLibrary.Data". This is how I always use it to access Sql Server 2005 or Express edition, do I need to do something different for sqlce here?
if I added the following line at the begining it will work fine but I don't want to define the connection string here since I did already in app.config:
SqlCeDatabase db = new SqlCeDatabase(@"Data Source=D:\Data\ce\dbfile.sdf");
I mentioned this quite some time ago in the issue tracker:
and just realized nobody ever commented on it. I assume it was never resolved.
The solution is to add a ProviderMapping that you can do graphically from the Config Tool:
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=184.108.40.206, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add databaseType="Microsoft.Practices.EnterpriseLibrary.Data.SqlCe.SqlCeDatabase, Microsoft.Practices.EnterpriseLibrary.Data.SqlCe, Version=220.127.116.11, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
A call to DatabaseFactory.CreateDatabase() should use the SqlCeDatabase Class.
However, you likely my want to use the SqlCeDatabase Class directly anyway since it has so many useful methods not in the Abstract Database Class.
Microsoft MVP C#