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模式运行的。