如何从桌面应用程序连接到移动设备上的 SDF?

发布于 2024-08-08 18:27:03 字数 1157 浏览 3 评论 0原文

Mobile 6.1 设备上的 C# WinForms .Net 3.5 到 SQL CE 3.5

我想在通过 ActiveSync 连接时,在我的 Windows Mobile 设备上建立从桌面应用程序到 SDF 数据库的连接。 Visual Studio 允许我创建到我的设备的数据连接。连接测试正常,我可以使用 Visual Studio 查看数据库中的数据。

然后我创建一个表单并尝试填充 DataGridView。当我运行该程序时,我收到一条错误消息,指出数据库的路径无效。

我应该如何在连接字符串中指定移动设备路径?

在我的 App.Config 中,我尝试了路径的变体,但它们都不起作用:

connectionString="Data Source=Mobile Device\Program Files\SqlCeViaActiveSync\Orders.sdf"

connectionString="Data Source=\Mobile Device\Program Files\SqlCeViaActiveSync\Orders.sdf"

connectionString="Data Source=Program Files\SqlCeViaActiveSync\Orders.sdf"

connectionString="Data Source=\Program Files\SqlCeViaActiveSync\Orders.sdf"

完整的连接字符串部分如下所示:

<connectionStrings>
    <add name="SqlCeViaActiveSync.Properties.Settings.OrdersConnectionString"
        connectionString="Data Source=Mobile Device\Program Files\SqlCeViaActiveSync\Orders.sdf"
        providerName="Microsoft.SqlServerCe.Client.3.5" />
</connectionStrings>

另外,我确实引用了 Microsoft.SqlServerCe.Client,因为我发现了几篇文章那提到这是必要的。

谁能指出我最近的一些文章/样本或让我知道我做错了什么?

谢谢!

C# WinForms .Net 3.5 to SQL CE 3.5 on Mobile 6.1 Device

I'd like to make a connection from a desktop application to a SDF database on my Windows Mobile device while it's connected via ActiveSync. Visual Studio lets me create a Data Connection to my device. The connections tests OK and I can view the data in the database using Visual Studio.

I then create a form and try to fill a DataGridView. When I run the program I get an error that the path to the data base is not valid.

How am I supposed to specify the Mobile device path in the connection string?

In my App.Config, I've tried variations on the path, but none of them work:

connectionString="Data Source=Mobile Device\Program Files\SqlCeViaActiveSync\Orders.sdf"

connectionString="Data Source=\Mobile Device\Program Files\SqlCeViaActiveSync\Orders.sdf"

connectionString="Data Source=Program Files\SqlCeViaActiveSync\Orders.sdf"

connectionString="Data Source=\Program Files\SqlCeViaActiveSync\Orders.sdf"

The full connection string section looks like this:

<connectionStrings>
    <add name="SqlCeViaActiveSync.Properties.Settings.OrdersConnectionString"
        connectionString="Data Source=Mobile Device\Program Files\SqlCeViaActiveSync\Orders.sdf"
        providerName="Microsoft.SqlServerCe.Client.3.5" />
</connectionStrings>

Also, I did make a reference to Microsoft.SqlServerCe.Client, as I found a few articles that mentioned it was necessary.

Can anyone point me to some recent articles/samples or let me know what I'm doing wrong?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

舟遥客 2024-08-15 18:27:03

我刚刚发现以下内容有效:

SqlCeConnection conn = new SqlCeConnection(@"Data Source='Mobile Device\Program Files\SqlCeViaActiveSync\Orders.sdf';");
        conn.Open();
        using (SqlCeTransaction trans = conn.BeginTransaction())
        {
            using (SqlCeCommand cmd = conn.CreateCommand())
            {
                cmd.CommandText = "SELECT [OrderNumber] FROM [Orders];";
                trans.Commit();
                SqlCeDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    this.listBox1.Items.Add((string)dr["OrderNumber"]);
                }

                MessageBox.Show(dr.RecordsAffected.ToString());
            }
        }
        conn.Close();

这并不完全是我正在寻找的内容,但适用于此应用程序。

I just found that the following works:

SqlCeConnection conn = new SqlCeConnection(@"Data Source='Mobile Device\Program Files\SqlCeViaActiveSync\Orders.sdf';");
        conn.Open();
        using (SqlCeTransaction trans = conn.BeginTransaction())
        {
            using (SqlCeCommand cmd = conn.CreateCommand())
            {
                cmd.CommandText = "SELECT [OrderNumber] FROM [Orders];";
                trans.Commit();
                SqlCeDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    this.listBox1.Items.Add((string)dr["OrderNumber"]);
                }

                MessageBox.Show(dr.RecordsAffected.ToString());
            }
        }
        conn.Close();

It wasn't exactly what I was looking for but will work for this application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文