带有MS SQL Server Compact 3.5 SP2的LINQ2SQL:BadImageFormatException [英] LINQ2SQL with MS SQL Server Compact 3.5 SP2: BadImageFormatException

查看:90
本文介绍了带有MS SQL Server Compact 3.5 SP2的LINQ2SQL:BadImageFormatException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在Ling2SQL中使用.sdf数据库文件.我正在.NET 3.5上使用VS2010.到目前为止,我所做的事情:

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. 创建sdf文件并添加表和数据(位于项目文件夹中)
  2. 将SQLMetal.exe和SqlMetal.exe.config复制到项目文件夹,并使用以下命令调用它:

  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

  • 将dbml文件添加到项目中(创建了designer.cs)

  • Added dbml file to the project (designer.cs is created)

    向designer.cs添加新方法

    Add new method to designer.cs

    public DataOfflineDataContext() : 
            base(global::CTcalc.Properties.Settings.Default.databaseOfflineConnectionString, mappingSource)
    {
        OnCreated();
    }
    

  • 将connectionString添加到设置文件(类型:connectionString)

  • Add connectionString to settings file (type:connectionString)

    Data Source=|DataDirectory|\database.sdf
    

  • 使用连接:

  • Using the connection:

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

  • 在调试我的项目时,我收到一个BadImageFormatException错误,其HRESULT:0x8007000B

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

    我不知道如何解决它.有帮助吗?

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

    推荐答案

    我的错误是在项目中使用了错误的.dll.

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

    我用过

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

    代替

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

    现在可以正常工作了!

    这篇关于带有MS SQL Server Compact 3.5 SP2的LINQ2SQL:BadImageFormatException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆