我尝试实现从SQLServer 2005同步数据到SQL Server CE时出现未处理的错误"未处理的SqlCeException".HResult值为"-2147024891",错误描述为“位于 System.Data.SqlServerCe.NativeMethods.CheckHRESULT()\r\n位于 System.Data.SqlServerCe.SqlCeRemoteDataAccess.Pull()\r\n位于 SmartDeviceProject2.Form1.button1_Click()\r\n位于 System.Windows.Forms.Control.OnClick()\r\n位于 System.Windows.Forms.Button.OnClick()\r\n位于 System.Windows.Forms.ButtonBase.WnProc()\r\n位于 System.Windows.Forms.Control._InternalWnProc()\r\n位于 Microsoft.AGL.Forms.EVL.EnterMainLoop()\r\n位于 System.Windows.Forms.Application.Run()\r\n位于 SmartDeviceProject2.Program.Main()\r\n”。
以下是代码:
SqlCeRemoteDataAccess rda = new SqlCeRemoteDataAccess("http://192.168.0.254/sqlce/sqlcesa30.dll", @"Data Source='\SmartDeviceProject2\Devices.sdf';Password=liuhua"); rda.InternetLogin = ""; rda.InternetPassword = ""; string dbConnStr = @"Provider=SQLOLEDB;Data Source=192.168.0.19;Initial Catalog=Devices;Persist Security Info=false;User ID=sa;Password=liuhua;"; rda.Pull("Device1", "select * from Device1", dbConnStr, RdaTrackOption.TrackingOn); rda.Dispose();
这个问题困扰了我两天,后来发现,原因在于sqlerver2005服务器端工具版本不对。我要连接SQLServer 2005,应该用3.5的SSCEServerTools-CHS.msi。更新ServerTools后,重新用Web同步向导布置IIS中的虚拟目录后,就能够同步数据了。
SqlCeRemoteDataAccess rda = new SqlCeRemoteDataAccess("http://192.168.0.254/sqlce2/sqlcesa35.dll", @"Data Source='\SmartDeviceProject2\Devices.sdf';Password=liuhua"); rda.InternetLogin = ""; rda.InternetPassword = ""; string dbConnStr = @"Provider=SQLOLEDB;Data Source=192.168.0.19;Initial Catalog=Devices;Persist Security Info=false;User ID=sa;Password=liuhua;"; rda.Pull("Device1", "select * from Device1", dbConnStr, RdaTrackOption.TrackingOn); rda.Dispose();
解决问题时参考了一篇文章 http://wenku.baidu.com/view/3a3c712cb4daa58da0114a27.html