LLBLGen with SQL CE

Posts   
 
    
Posts: 8
Joined: 21-Oct-2009
# Posted on: 12-Nov-2009 14:04:42   

Hi all

Let me start by saying that I'm currently evaluating LLBLGen 2.6 for use in my company on a number of different projects. So far I'm very impressed, and will almost certainly purchasing it.

A new project has landed on my desk for which the most appropriate solution seems to be a winforms app using an MS SQL CE 3.5 database.

I've looked through the manual and the forum posts, but I'm having difficulty in finding out exactly what I need to do to have LLBLGen work with SQL CE.

When I go to create a new project, there is no option for CE in the dropdown - am I missing something because I only have the demo? I'm not sure what I have to do to set up a project of this type.

At a very basic level, how do I create a new project for use with SQL CE?, how do I make that look at my SDF file?

I apologise if I'm being particularly dumb, but would very much appreciate your help with this.

Kind regards

Richard Egginton

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 12-Nov-2009 14:24:56   

I think you want to use SQL CE Desktop, however it's not clear from your post, could you elaborate a bit on that? (it's important, as we also support SQL CE on windows mobile)

Frans Bouma | Lead developer LLBLGen Pro
Posts: 8
Joined: 21-Oct-2009
# Posted on: 12-Nov-2009 14:33:47   

Otis wrote:

I think you want to use SQL CE Desktop, however it's not clear from your post, could you elaborate a bit on that? (it's important, as we also support SQL CE on windows mobile)

Otis

Apologies for being vague.

My project is indeed going to use SQL CE Desktop.

Thanks

Posts: 8
Joined: 21-Oct-2009
# Posted on: 12-Nov-2009 18:01:56   

I've actually managed to make some progress on this, but have hit another problem.

What I did was to create a new LLBLGen project pointing at a SQL Express 2008 database

I generated the code specifying CF 3.5 as the Target Platform and SelfServicing as the Template Group.

After the code was generated I used Primeworks Data Port Wizard to create a SQL Server CE 3.5 database file from my SQL Server Express 2008 database.

In Visual Studio, I have a WinForms application which references both my compiled LLBLGen library, and the appropriate SD.LLBLGen.Pro.DQE.SqlServerCE.CF35 and SD.LLBLGen.Pro.ORMSupportClasses.CF35 libraries.

in my app.config, I have the following settings:

<add key="Main.ConnectionString" value="Data Source=E:\BeanCounter.sdf;"/> <add key="SqlServerDQECompatibilityLevel" value="4" />

My Win Forms application is a simple single form app containing a DataGridView to which I am trying to bind a basic set of data as follows:

dataGridView1.DataSource = UsersCollection.GetMultiAsDataTable(null, 100, null);

However, at runtime, this line of code produces the following error:

"The ConnectionString property has not been initialized."} System.Exception {System.InvalidOperationException}

at System.Data.SqlServerCe.SqlCeConnection.Open(Boolean silent)\r\n at System.Data.SqlServerCe.SqlCeConnection.Open()\r\n at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.ExecuteMultiRowDataTableRetrievalQuery(IRetrievalQuery queryToExecute, DbDataAdapter dataAdapterToUse, DataTable tableToFill, IEntityFields fieldsToReturn)\r\n at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.PerformGetMultiAsDataTableAction(IEntityFields fieldsToReturn, DataTable tableToFill, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPredicate selectFilter, IRelationCollection relations, Boolean allowDuplicates, IGroupByCollection groupByClause, ITransaction transactionToUse, Int32 pageNumber, Int32 pageSize)\r\n at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.PerformGetMultiAsDataTableAction(Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPredicate selectFilter, IRelationCollection relations, Int32 pageNumber, Int32 pageSize)\r\n at DNC.BeanCounter.LLBLGen.DaoClasses.UsersDAO.GetMultiAsDataTable(Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPredicate selectFilter, IRelationCollection relations, Int32 pageNumber, Int32 pageSize) in E:\Does Not Compute Ltd\BeanCounter\Source\Trunk\DNC.BeanCounter\DNC.BeanCounter.LLBLGen\DaoClasses\UsersDAO.cs:line 69\r\n at DNC.BeanCounter.LLBLGen.CollectionClasses.UsersCollection.GetMultiAsDataTable(IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relations, Int32 pageNumber, Int32 pageSize) in E:\Does Not Compute Ltd\BeanCounter\Source\Trunk\DNC.BeanCounter\DNC.BeanCounter.LLBLGen\CollectionClasses\UsersCollection.cs:line 162\r\n at DNC.BeanCounter.LLBLGen.CollectionClasses.UsersCollection.GetMultiAsDataTable(IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses) in E:\Does Not Compute Ltd\BeanCounter\Source\Trunk\DNC.BeanCounter\DNC.BeanCounter.LLBLGen\CollectionClasses\UsersCollection.cs:line 137\r\n at DNC.BeanCounter.App.Form1.crap() in E:\Does Not Compute Ltd\BeanCounter\Source\Trunk\DNC.BeanCounter\DNC.BeanCounter.App\Form1.cs:line 26" string

Can anyone point me in the right direction?

Thanks

Posts: 8
Joined: 21-Oct-2009
# Posted on: 12-Nov-2009 23:04:32   

I think I've managed to sort this out myself by adding the following line of code.

DbUtils.ActualConnectionString = System.Configuration.ConfigurationSettings.AppSettings["Main.ConnectionString"].ToString();

Can anyone confirm if this is 'best-practice' or suggest a better solution?

Thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Nov-2009 04:35:04   

Hi Richard,

This is what you have to do to get it working:

  1. Create your SQL Server databser (DONE)

  2. Create your LLBLGen Project based on your SQL Server DB (DONE)

  3. Generate code using **.NET 2.0 or higher **as the target platform. Don't generate to CF target platform.

  4. Use the normal LLBLGen runtime assemblies (not the CF variations). You should reference **SD.LLBLGen.Pro.DQE.SqlServer.NET20 **and SD.LLBLGen.Pro.ORMSupportClasses.NET20. So please correct the references.

  5. Specify the compatibility level to CE Desktop. (DONE)

<add key="SqlServerDQECompatibilityLevel" value="4" />
  1. Specify the connection string.
<add key="Main.ConnectionString"  value="data source=c:\pathtodb\Northwind.sdf;"/>

Check the manual for more info.

David Elizondo | LLBLGen Support Team
Posts: 8
Joined: 21-Oct-2009
# Posted on: 13-Nov-2009 09:19:52   

Daelmo

Many thanks for providing the appropriate steps to getting this to work.

Apologies for the multiple posts - I didn't mean to, its just that each time I posted I kept getting the generic web.Config error page and I wasn't sure if it was posting ok.

Once again, many thanks for your help.