LINQ2SQL with MS SQL Server Compact 3.5 SP2: BadIm

2019-08-17 01:30发布

I am having trouble using a .sdf database file with Ling2SQL. I am working with VS2010 on .NET 3.5. What I have done so far:

  1. Created sdf file and added tables and data (located in project folder)
  2. Copied SQLMetal.exe and SqlMetal.exe.config to the project folder and called it with:

    SQLMetal.exe database.sdf /dbml:DataOffline.dbml /namespace:CTcalc /pluralize
    
  3. Added dbml file to the project (designer.cs is created)

  4. Add new method to designer.cs

    public DataOfflineDataContext() : 
            base(global::CTcalc.Properties.Settings.Default.databaseOfflineConnectionString, mappingSource)
    {
        OnCreated();
    }
    
  5. Add connectionString to settings file (type:connectionString)

    Data Source=|DataDirectory|\database.sdf
    
  6. Using the connection:

    using (DataOfflineDataContext dc = new DataOfflineDataContext())
                lProtFunc = (from c in dc.ProtectionFunctions select c).ToList();
    

When debugging my project, I get an BadImageFormatException error with HRESULT: 0x8007000B

I have no idea how to fix it. Any help?

2条回答
Animai°情兽
2楼-- · 2019-08-17 01:43

My fault was using the wrong .dll within my project.

I used

Program Files\Microsoft SQL Server Compact Edition\v3.5\Desktop\System.Data.SqlServerCe.dll

instead of

Program Files\Microsoft SQL Server Compact Edition\v3.5\Private\System.Data.SqlServerCe.dll

Now it is working!

查看更多
别忘想泡老子
3楼-- · 2019-08-17 02:09

You must install both the x86 and x64 runtimes on your x64 system - http://www.microsoft.com/download/en/details.aspx?id=5783

查看更多
登录 后发表回答