程序文件中的mobile数据库是pubmobile.sdf
包含 System.Data.SqlServerCe命名空间
访问服务器中的数据库 pubsample.mdf
在vs2005 建立用C#语言编写的wince 5.0 设备应用程序
copy MSDN中的文档粘贴后修改
在PDA上运行后弹出如下错误:
“SQL Mobile encountered problems when opening the database”
以下为代码:
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 DeviceApplication4 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { // Connection String to the SQL Server // string rdaOleDbConnectString = "Integrated Security=SSPI;Provider=sqloledb;Data Source=werewolf;Initial Catalog=pubsample; " + "User Id=sa;Password = cedb"; // Initialize RDA Object // SqlCeRemoteDataAccess rda = null; try { // Try the Pull Operation // rda = new SqlCeRemoteDataAccess( "http://werewolf/pub/sqlcesa30.dll", "", "", "Data Source=pubmobile.sdf"); rda.Pull("Table_1", "SELECT * FROM Table_1", rdaOleDbConnectString, RdaTrackOption.TrackingOnWithIndexes, "ErrorTable"); // or, try one of these overloads: // // rda.Pull("Employees", "SELECT * FROM DimEmployee", rdaOleDbConnectString, // RdaTrackOption.TrackingOnWithIndexes); // // rda.Pull("Employees", "SELECT * FROM DimEmployee", rdaOleDbConnectString); } catch (SqlCeException err) { // Handle errors here // MessageBox.Show(err.Message, "错误"); } finally { // Dispose of the RDA object // rda.Dispose(); } } } }
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 DeviceApplication4
{
public partial class Form1 : Form
public Form1()
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
// Connection String to the SQL Server
//
string rdaOleDbConnectString = "Integrated Security=SSPI;Provider=sqloledb;Data Source=werewolf;Initial Catalog=pubsample; " +
"User Id=sa;Password = cedb";
// Initialize RDA Object
SqlCeRemoteDataAccess rda = null;
try
// Try the Pull Operation
rda = new SqlCeRemoteDataAccess(
"http://werewolf/pub/sqlcesa30.dll",
"",
"Data Source=pubmobile.sdf");
rda.Pull("Table_1", "SELECT * FROM Table_1", rdaOleDbConnectString,
RdaTrackOption.TrackingOnWithIndexes, "ErrorTable");
// or, try one of these overloads:
// rda.Pull("Employees", "SELECT * FROM DimEmployee", rdaOleDbConnectString,
// RdaTrackOption.TrackingOnWithIndexes);
// rda.Pull("Employees", "SELECT * FROM DimEmployee", rdaOleDbConnectString);
catch (SqlCeException err)
// Handle errors here
MessageBox.Show(err.Message, "错误");
finally
// Dispose of the RDA object
rda.Dispose();