在64位平台使用SQL Server Compact

今天在 Windows 7 x64 使用 Visual Studio 2008 开发了一个很简单的 SQL Server Compact 3.1 桌面应用程序,发现跑不起来。抛出以下异常:
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt   Message: " An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) "

  StockTrace:

  StockTrace

  System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT:
0x8007000B )

  at System.Data.SqlServerCe.NativeMethods.CreateErrorInstance(IntPtr
& pError)

  at System.Data.SqlServerCe.SqlCeCommand..ctor()

  at WindowsApplication1.NorthwindDataSetTableAdapters.EmployeesTableAdapter.InitAdapter()
in D:\Documents\Visual Studio 2005 \Projects\WindowsApplication1\WindowsApplication1\NorthwindDataSet.Designer.cs:line 6400

  at WindowsApplication1.NorthwindDataSetTableAdapters.EmployeesTableAdapter.get_Adapter()
in D:\Documents\Visual Studio 2005 \Projects\WindowsApplication1\WindowsApplication1\NorthwindDataSet.Designer.cs:line 6324

  at WindowsApplication1.NorthwindDataSetTableAdapters.EmployeesTableAdapter.Fill(EmployeesDataTable dataTable)
in D:\Documents\Visual Studio 2005 \Projects\WindowsApplication1\WindowsApplication1\NorthwindDataSet.Designer.cs:line 6607

  at WindowsApplication1.Form1.Form1_Load(Object sender, EventArgs e)
in D:\Documents\Visual Studio 2005 \Projects\WindowsApplication1\WindowsApplication1\Form1.cs:line 29

  at System.Windows.Forms.Form.OnLoad(EventArgs e)

  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.Control.ControlNativeWindow.WndProc(Message
& m)

  at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

 

  仔细想了想,SQL Server Compact 3.5 SP1 才开始本机支持64位平台,那么 SQL Server Compact 3.1和3.5应该只能通过WOW64模式运行。WOW64 是一个允许32位应用程序运行在64位平台的仿真层,让它们好像是在32位平台上运行。

  经过在网络上查找,也有其他人遇到过类似的问题,一般的回答都是安装64位版本的 SQL Server Compact 3.5 SP1,可是我现在要解决的是 SQL Server Compact 3.1。后来在这里找到了解决的方法!Visual Studio 2005/2008 创建的项目默认的目标平台是“Any CPU”,将它改为x86就可以了,这样编译后的程序是通过WOW64模式运行的。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22903848/viewspace-620683/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/22903848/viewspace-620683/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值