LINQ2SQL with MS SQL Server Compact 3.5 SP2: BadImageFormatException

妖精的绣舞 提交于 2019-12-12 04:38:16

问题


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?


回答1:


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




回答2:


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!



来源:https://stackoverflow.com/questions/9226180/linq2sql-with-ms-sql-server-compact-3-5-sp2-badimageformatexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!