Invalid Cast Exception with CF 2.0 and LLBL Gen Pro 2.6

Posts   
 
    
AGoyal
User
Posts: 25
Joined: 06-Oct-2008
# Posted on: 06-Oct-2008 21:59:14   

Hello,

I have just started using LLBl Gen to see what kind of Pocket PC and SQL CE 3.5 SP1 support is available. I created a sample app for that and used following code to read value out of SDF (created using Microsoft Sync Services for ADO.Net):

try { //get the database connection

            //setup filter
            RelationPredicateBucket filter = new RelationPredicateBucket(HarvestNotificationFields.ConfirmationNumber == 4);//new RelationPredicateBucket(new FieldBetweenPredicate(HarvestNotificationFields.ConfirmationNumber,3,5));
            EntityCollection<HarvestNotificationEntity> harvestNotifications = new EntityCollection<HarvestNotificationEntity>();
            //fetch them using a DataAccessAdapter instance

            using (DataAccessAdapter adapter = new DataAccessAdapter("Data Source =/Temp/IFRISMobile.sdf"))
            {
                adapter.FetchEntityCollection(harvestNotifications, null);

            }

            listProgress.Items.Add("Number of entities fetched: " + harvestNotifications.Count);

            //Display for each harvest notification fetched the harvest notification id
            foreach (HarvestNotificationEntity hn in harvestNotifications)
            {
                listProgress.Items.Add(hn.HarvestNotificationId.ToString());
            }
           // Console.ReadLine();

            //Change CountyFips for each harvest notification
            foreach (HarvestNotificationEntity hn in harvestNotifications)
            {
                hn.CountyFips = "51001";
            }

            //Save changes to DB
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.SaveEntityCollection(harvestNotifications);
            }

           listProgress.Items.Add("Saved Harvest Notifications");

        }

        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

However I keep getting following exception at FetchEntityCollection statement:

Invalid Cast Exception at:

"at System.Data.SqlServerCe.SqlCeCommand.set_DbConnection()\r\nat System.Data.Common.DbCommand.System.Data.IDbCommand.set_Connection()\r\nat SD.LLBLGen.Pro.ORMSupportClasses.Query..ctor()\r\nat SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery..ctor()\r\nat SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreateSelectDQ()\r\nat SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateSelectDQ()\r\nat SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreatePagingSelectDQ()\r\nat SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateSelectDQ()\r\nat SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.CreateSelectDQ()\r\nat SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollectionInternal()\r\nat SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection()\r\nat SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection()\r\nat MobilePrototype.frmTestLLBLGen.mnuTest_Click()\r\nat System.Windows.Forms.MenuItem.OnClick()\r\nat System.Windows.Forms.Menu.ProcessMnuProc()\r\nat System.Windows.Forms.Form.WnProc()\r\nat System.Windows.Forms.Control._InternalWnProc()\r\nat Microsoft.AGL.Forms.EVL.EnterMainLoop()\r\nat System.Windows.Forms.Application.Run()\r\nat MobilePrototype.Program.Main()\r\n"

I would appreciate if you can please help me with this.

Thanks

Apurv

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 07-Oct-2008 08:49:49   

LLBLGenPro version and RuntimeLibraries build version (http://llblgen.com/TinyForum/Messages.aspx?ThreadID=7722) ?

David Elizondo | LLBLGen Support Team
AGoyal
User
Posts: 25
Joined: 06-Oct-2008
# Posted on: 07-Oct-2008 17:01:44   

v 2.6 (demo) and

SD.LLBLGen.Pro.DQE.SqlServerCE.CF20 (v 2.6) SD.LLBLGen.Pro.ORMSupportClasses.CF20 (v 2.6)

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 07-Oct-2008 17:14:02   

Please check the link posted by David, and specify the exact RuntimeLibraries build version.

AGoyal
User
Posts: 25
Joined: 06-Oct-2008
# Posted on: 07-Oct-2008 17:17:20   

SD.LLBLGen.Pro.DQE.SqlServerCE.CF20 : version 2.6.0.0 SD.LLBLGen.Pro.ORMSupportClasses.CF20 : version 2.6.0.0

Thanks

AGoyal
User
Posts: 25
Joined: 06-Oct-2008
# Posted on: 07-Oct-2008 22:15:29   

Here is the my table structure:

TABLE [gisadmin].[tbl_harvest_notification]( [audit_id] [uniqueidentifier] NOT NULL, [harvest_id] [uniqueidentifier] NULL, [county_fips] char NULL, [harvest_notif_acres] [decimal](6, 1) NULL, [harvest_start_date] [datetime] NULL, [harvest_notif__date] [datetime] NOT NULL, [harvest_notif__user_id] [uniqueidentifier] NOT NULL, [harvest_notif_confirmation_num] varchar NOT NULL, [harvest_notif_mail_planning_maps] [bit] NOT NULL, [harvest_notif_driving_directions] varchar NULL, [harvest_notif_lat_degrees] [int] NULL, [harvest_notif_lat_minutes] [int] NULL, [harvest_notif_lat_seconds] [decimal](2, 2) NULL, [harvest_notif_long_degrees] [int] NULL, [harvest_notif_long_minutes] [int] NULL, [harvest_notif_long_seconds] [decimal](2, 2) NULL, [harvest_notif_state_route_num] varchar NULL, [harvest_notif_xsec_road1] varchar NULL, [harvest_notif_xsec_road2] varchar NULL, [harvest_notif_miles_from_xsec] [decimal](2, 1) NULL, [harvest_notif_direction_from_xsec] varchar NULL, [harvest_notif__method] varchar NULL,

Also here is the App.Config that I modified for DBSpecific project:

<?xml version="1.0"?> <configuration> <appSettings> <!--add key="Main.ConnectionString" value="data source=dev-db03;initial catalog=VDOF_IFRIS_V2;User ID=gisadmin;Password=d0wnt0wndev;persist security info=False;packet size=4096"/--> <add key="Main.ConnectionString" value="Data Source =/Temp/IFRISMobile.sdf"/> </appSettings> </configuration>

I even tried leaving the default Main.ConnectionString key in there but got the same error.

Thanks

AGoyal
User
Posts: 25
Joined: 06-Oct-2008
# Posted on: 07-Oct-2008 22:17:31   

Forgot to mention that I added following columns as well to this table for sync services:

[update_originator_id] [int] NULL DEFAULT ((0)), [update_timestamp] [timestamp] NOT NULL, [create_timestamp] [bigint] NULL DEFAULT (@@dbts+(1)),

AGoyal
User
Posts: 25
Joined: 06-Oct-2008
# Posted on: 07-Oct-2008 22:37:43   

I even tried a simple look up table with following structure and code but got the same error:

Table Structure:

TABLE [gisadmin].[tbl_lu_harvest_notification_method]( [harvest_notification_method] varchar NOT NULL, [notification_method_display_order] [int] NOT NULL, [notification_method_start_date] [datetime] NOT NULL, [notification_method_end_date] [datetime] NULL, [update_timestamp] [timestamp] NOT NULL, [create_timestamp] [bigint] NULL DEFAULT (@@dbts+(1)),

Code: EntityCollection<LuHarvestNotificationMethodEntity> harvestNotificationMethods = new EntityCollection<LuHarvestNotificationMethodEntity>();

            using (DataAccessAdapter adapter = new DataAccessAdapter("Data Source =/Temp/IFRISMobile.sdf", true))
            {
                adapter.CatalogNameToUse = "gisadmin.";

                adapter.FetchEntityCollection(harvestNotificationMethods, null);

            }

            listProgress.Items.Add("Number of entities fetched: " + harvestNotificationMethods.Count);

            //Display for each harvest notification fetched the harvest notification id
            foreach (LuHarvestNotificationMethodEntity hn in harvestNotificationMethods)
            {
                listProgress.Items.Add(hn.HarvestNotificationMethod.ToString());
            }
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-Oct-2008 07:26:33   

AGoyal wrote:

SD.LLBLGen.Pro.DQE.SqlServerCE.CF20 : version 2.6.0.0 SD.LLBLGen.Pro.ORMSupportClasses.CF20 : version 2.6.0.0

When it's a problem occuring at runtime, post the Runtime library version. The runtime library version is obtainable by rightclicking the SD.LLBLGen.Pro.ORMSupportClasses.NETxy.dll in windows explorer and then by selecting properties and the version tab. The version is then enlisted at the top as the fileversion. It has the typical format as 2.0.0.YYMMDD, or starting in 2007, the format 2.0.YY.MMDD

Anyway. It might be you are referencing the wrong DQE. You has to reference the specific CE DQE for CF.NET, not the ordinairy Sqlserver DQE at your DBSpecific project. Please check that.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39863
Joined: 17-Aug-2003
# Posted on: 08-Oct-2008 10:01:29   

Also check if you're referring the correct CF.NET build, namely the 35 one, for CF.NET 3.5.

Also, be sure you reference the correct SqlServerCE provider dll (namely the one for CE 3.5, for compact framework)

Frans Bouma | Lead developer LLBLGen Pro
AGoyal
User
Posts: 25
Joined: 06-Oct-2008
# Posted on: 08-Oct-2008 13:11:51   

I am using CF2.0 and SqlServer CE 3.5. We cannot use CF 3.5 for our project. I did build the DB specific project with SQL CE 3.5 SP1 reference.

AGoyal
User
Posts: 25
Joined: 06-Oct-2008
# Posted on: 08-Oct-2008 13:19:19   

I checked the file version for the runtime libraries in the windows explorer

SD.LLBLGen.Pro.DQE.SqlServerCE.CF20.dll

and

SD.LLBLGen.Pro.ORMSupportClasses.CF20.dll

and it is 2.6.0.0

Thanks

AGoyal
User
Posts: 25
Joined: 06-Oct-2008
# Posted on: 08-Oct-2008 16:19:41   

So it finally worked if I use CF 3.5 with SQL CE 3.5 but doesnt work if I use CF 2.0 with SQL CE3.5!!

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 08-Oct-2008 17:21:29   

CE 3.5 MOBILE is supported on CF.NET 3.5 by default, but NOT on CF.NET 2.0. You run into the problem where you reference the CE3.5 provider dll: "C:\Program Files\Microsoft SQL Server Compact Edition\v3.5\Devices\Client\System.Data.SqlClient.dll" and you also reference the CE DQE for CF.NET 2.0, which is build against the CE3.0 provider "C:\Program Files\Microsoft Visual Studio 8\SmartDevices\SDK\SQL Server\Mobile\v3.0\System.Data.SqlServerCe.dll"

This is done this way because it otherwise would require a lot of different builds and CE 3.5 was released with vs.net 2008 anyway. We can create a custom build for you, but we actually would like to see you upgrade to .net 3.5 or downgrade to CE 3.0

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39863
Joined: 17-Aug-2003
# Posted on: 09-Oct-2008 10:31:04   

I wished it was a different story, but MS thought it was better to have a weird path of versioning of CE providers.

I understand why you would use CE 3.5, as CE 3.0/1 is utterly crap, however so is their provider assembly.

Frans Bouma | Lead developer LLBLGen Pro