1。首先,如果沒有安裝IIS,需要先安裝IIS。XP使用安裝盤來安裝。
如果環境是windows 2008的IIS7,在安裝下面的時候會出現會要首先安裝(IIS 6.0) backward compatibility components的錯誤訊息,解決方案是要先安裝IIS 6 Management Compatibility,請參考:
http://support.microsoft.com/default.aspx?scid=kb;en-us;955966&sd=rss&spid=2855
2。下載並安裝SQL Server Compact 3.5 Service Pack 1 Server Tools。
是
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=fa751db3-7685-471b-ac31-f1b150422462#filelist
3。配置SQL Server Compact 3.5 Service Pack 1 Server Tools。
在開始菜單程式裡運行SQL Server Compact 3.5 下面的Configure Web Synchronization Wizard(配置web同步精靈)。
4。在行動裝置上安裝sqlserver compact 3.5。
分為手動安裝和自動安裝。
自動安裝:
如果使用 Microsoft Visual Studio 產生一個使用 Microsoft SQL Server Compact 3.5 (SQL Server Compact 3.5)並與 .NET 連線應用程式程式,則當您第一次在裝置上部署該應用程式時,會自動在裝置上安裝 SQL Server Compact 3.5 引擎。
手動安裝:
可以通過手動將 .cab 檔案複製到裝置上,在裝置上安裝 SQL Server Compact 3.5。 如果是產生本機應用程式,則必須手動複製 .cab 檔案。
請參考以下的文章: 如何選擇正確的SQL Server Compact安裝包
5。在SQL Server伺服器上建立資料庫mymoney供測試用,其中包含一個表record。欄位資訊是:
id int notnull pk 要使用RDA,必須對錶設定主鍵
action varchar(50) notnull
cost money notnull
6。編程實現RDA。
用VS2008編寫一個行動裝置應用程式,以下是在Form中實現的代碼,以下代碼在IPAQ上運行成功。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlServerCe;
namespace SmartDeviceProject1
{
public partial class Form1 : Form
{
// DataSource中的n28201是IIS伺服器和Sql Server的主機名稱。
private string sCon = @"Provider=SQLOLEDB;Data Source=n28201;"
+ @"Initial Catalog=mymoney;"
+ @"integrated security=SSPI;Persist Security Info=False";
//test是虛擬目錄名
private string internetUrl = @"http://n28201/test/sqlcesa35.dll";
private string localConnectionString = @"Data Source=/My Documents/mymoney.sdf";
//IIS使用的是基本驗證,需要提供以下Windows用的使用者名稱和密碼。
private string internetLogin = "sa";
private string internetPassword = "sa";
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// First, ensure you have an empty local SQL CE database.
if (System.IO.File.Exists(@"/My Documents/mymoney.sdf"))
{
System.IO.File.Delete(@"/My Documents/mymoney.sdf");
}
// Create new database.
SqlCeEngine eng = new SqlCeEngine(localConnectionString);
eng.CreateDatabase();
using (SqlCeRemoteDataAccess rda = new SqlCeRemoteDataAccess())
{
rda.InternetUrl = this.internetUrl;
rda.InternetLogin = this.internetLogin;
rda.InternetPassword = this.internetPassword;
rda.LocalConnectionString = localConnectionString;
try
{
rda.Pull("record", "SELECT * FROM record",
sCon, RdaTrackOption.TrackingOn, "rdaRecordErrors");
}
catch (SqlCeException sqlCeEx)
{
MessageBox.Show(sqlCeEx.ToString());
return;
}
finally
{
rda.Dispose();
}
MessageBox.Show("RDA Pull Done!");
}
}
private void button2_Click(object sender, EventArgs e)
{
using (SqlCeRemoteDataAccess rda = new SqlCeRemoteDataAccess())
{
rda.InternetUrl = this.internetUrl;
rda.InternetLogin = this.internetLogin;
rda.InternetPassword = this.internetPassword;
rda.LocalConnectionString = localConnectionString;
try
{
rda.Push("record", this.sCon);
}
catch (SqlCeException sqlCeEx)
{
MessageBox.Show(sqlCeEx.ToString());
return;
}
finally
{
rda.Dispose();
}
}
MessageBox.Show("RDA Push Done!");
}
private void button4_Click(object sender, EventArgs e)
{
using (SqlCeRemoteDataAccess rda = new SqlCeRemoteDataAccess())
{
rda.InternetUrl = this.internetUrl;
rda.InternetLogin = this.internetLogin;
rda.InternetPassword = this.internetPassword;
rda.LocalConnectionString = localConnectionString;
try
{
rda.SubmitSql("UPDATE record set cost=888 where id=1", this.sCon);
}
catch (SqlCeException sqlCeEx)
{
MessageBox.Show(sqlCeEx.ToString());
return;
}
finally
{
rda.Dispose();
}
}
MessageBox.Show("RDA SubmitSQL Done!");
}
private void button3_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
6。在XP上安裝ActiveSync4.5。
7。將行動裝置用USB串連到XP主機,使用VS2008將項目發布到行動裝置,運行成功。
pull運行成功後,在行動裝置中的mymoney.sdf中建立了rdaRecordErrors和record兩個表。