Embedding SQL Server CE 3.5

Posts   
 
    
pandu avatar
pandu
User
Posts: 86
Joined: 18-May-2006
# Posted on: 02-May-2009 12:38:22   

Hi:

I am developing a Desktop application using SQL Server CE 3.5 Database.

I have created the SQL Project to generate the code and changed the connection string in app.confing and set the compatibility to 4.

My requirement is that the client computer should use the CE 3.5 database without installing SQL Server CE 3.5.

When I launch the application, I get this error:

************** Exception Text **************
System.TypeInitializationException: The type initializer for 'SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine' threw an exception. ---> SD.LLBLGen.Pro.ORMSupportClasses.ORMGeneralOperationException: There's no ADO.NET provider defined / found for the compatibility level 'SqlServerCE35'. Please make sure either the machine.config or this application's .config file contains a definition of the provider.
   at SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.SetFactoryToUse()
   at SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.set_CompatibilityLevel(SqlServerCompatibilityLevel value)
   at SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine..cctor()
   --- End of inner exception stack trace ---
   at SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine..ctor()
   at ES.ABC.DAL.DatabaseSpecific.DataAccessAdapter.CreateDynamicQueryEngine() in D:\ABCDAL.CE\DatabaseSpecific\DataAccessAdapter.cs:line 458
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.CreateSelectDQ(IEntityFields2 fieldsToFetch, IFieldPersistenceInfo[] persistenceInfoObjects, IPredicateExpression filter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollectionInternal(IEntityCollection2 collectionToFill, IRelationPredicateBucket& filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket)
   at ABCClient.BusinessLayer.XManager.FetchXCollection() in D:\Projects\ABCClient\ABCClient\BusinessLayer\XManager.cs:line 65
   at ABCClient.frmMain.SetGlobalYCode() in D:\Projects\ABCClient\ABCClient\frmMain.cs:line 89
   at ABCClient.frmMain.frmMain_Load(Object sender, EventArgs e) in D:\Projects\ABCClient\ABCClient\frmMain.cs:line 76
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

I do build LLBL Dlls outside of the project and reference them in my application. When I build the LLBL Dlls, Do I need to reference any DLLs for CE support, so the application runs without installation of SQL Server CE 3.5 in client machine?

Thank you for your help.

PS: When I install SQLServer CE 3.5 in client's workstation, it works just fine. simple_smile

pandu avatar
pandu
User
Posts: 86
Joined: 18-May-2006
# Posted on: 02-May-2009 12:46:19   
SqlServerCe provider registration
It's no longer necessary to reference System.Data.SqlServerCe.dll, however on the machine the application is ran which uses compatibility level 3 or 4, this dll has to be installed as documented in the SqlServer CE Desktop documentation about deployment: via the .msi shipped with SqlServer CE Desktop. If you can’t run this .msi installer, be sure your application’s .config file contains the appropriate provider registration for the DbProviderFactory. (this information is installed in the machine.config file by the .msi installer of SqlServer CE Desktop). More details about this are available in the SqlServer CE Desktop documentation (the 'Books online' documents of SqlServer CE Desktop)

Based on the above info, I have even included the System.Data.SqlServerCe.dll in the application and it is installed when installing the application. But it doesn't help.

Thanks.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 03-May-2009 22:29:04   

This is copied from the manual:

SqlServerCe provider registration It's no longer necessary to reference System.Data.SqlServerCe.dll, however on the machine the application is ran which uses compatibility level 3 or 4, this dll has to be installed as documented in the SqlServer CE Desktop documentation about deployment: via the .msi shipped with SqlServer CE Desktop. If you can’t run this .msi installer, be sure your application’s .config file contains the appropriate provider registration for the DbProviderFactory. (this information is installed in the machine.config file by the .msi installer of SqlServer CE Desktop). More details about this are available in the SqlServer CE Desktop documentation (the 'Books online' documents of SqlServer CE Desktop)

Also look at these related threads: http://llblgen.com/tinyforum/Messages.aspx?ThreadID=13829 http://llblgen.com/tinyforum/Messages.aspx?ThreadID=12418

David Elizondo | LLBLGen Support Team
pandu avatar
pandu
User
Posts: 86
Joined: 18-May-2006
# Posted on: 05-May-2009 08:03:36   

http://llblgen.com/tinyforum/Messages.aspx?ThreadID=13829

This thread is close to what I was looking for.

This is what I did.

  1. I have a external Dummy Web Application that has two LLBL Projects added and referenced to create the DLL to its Bin. At this point, I do not reference any SQLServer CE Dlls here.

  2. In my Desktop Project, I have referenced the LLBL Dlls and SqlServerCe.dll and set the Build to "Content" and Copy Always. This ensure that the DLL is copied to my application root directory when installed. I even referenced all 7 Dlls from \Desktop directory of SQL Server CE directory installation and have set to copy to my app folder as well.

  3. I have changed my app.config and it looks like this:

<configuration>
  <appSettings>
    <add key="Main.ConnectionString" value="data source=C:\Data\TestCE.sdf"/>
    <add key="SqlServerDQECompatibilityLevel" value="4" />
  </appSettings>

<system.data>
    <DbProviderFactories>
        <remove invariant="System.Data.SqlServerCe.3.5" />
        <add name="Microsoft SQL Server Compact Data Provider" invariant="System.Data.SqlServerCe.3.5" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
    </DbProviderFactories>
</system.data>

</configuration>

I build the project and installed in a Virtual PC which doesn't have SQLServer CE installed.

When I run the app, I get the same error.

What am I missing?

confused

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 05-May-2009 09:38:23   

Take care of the version number:

<system.data>

<DbProviderFactories>

<remove invariant="System.Data.SqlServerCe.3.5" />

<add name="Microsoft SQL Server Compact Data Provider" invariant="System.Data.SqlServerCe.3.5" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>

</DbProviderFactories>

</system.data>

Try this Version=3.5.1.0

pandu avatar
pandu
User
Posts: 86
Joined: 18-May-2006
# Posted on: 05-May-2009 11:36:05   

THAT did the trick.

Thanks a lot.

smile