Compact Framework 3.5 - 数据集运行时连接字符串

发布于 2024-11-08 14:51:15 字数 419 浏览 2 评论 0原文

我发现了一篇 MS 文章,上面写着我可以使用 .XSD 文件的 ConnectionString 属性在运行时更改数据集的 ConnectionString。

这会在 .csproj 文件中设置一个名为“RuntimeConnectionString”的元素。

但是,当我将表适配器部署到 Motorola MC9190-G 设备 (Windows Mobile 6.5.1) 时,它不会更改表适配器的 ConnectionString。

我做错了什么,还是这是一个错误?使用 Compact Framework 更改运行时连接字符串的适当/替代选项是什么?

提前致谢

I found an MS article that says I can use the ConnectionString property of the .XSD file to change the DataSet's ConnectionString at run-time.

This sets an element in the .csproj file called "RuntimeConnectionString".

However, it doesn't change the tableadapters' ConnectionString when I deploy it to my Motorola MC9190-G device (Windows Mobile 6.5.1).

Am I doing something wrong, or is this a bug? What are the appropriate/alternate options to change the connection string for run-time with Compact Framework?

Thanks in Advance

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

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

发布评论

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

评论(1

梦中楼上月下 2024-11-15 14:51:15

我花了一整天的时间寻找这个问题的解决方案。
看起来这是一个 Visual Studio 错误(我使用 VS2008Professional 并且也被困在这个问题上)。
在这种情况下,两种可能的操作是:
1)在构建TA之前(实际上在打开与数据库的连接之前)手动更改tableAdapter(TA)连接字符串。

// something like this:
if (storageDataSetUtil.DesignerUtil.IsRunTime())
{
    // path to database file in my mobile device
    this.employeesTableAdapter.Connection.ConnectionString = @"/Program Files/MyApp/data/storage.s3db";

    // VS2008-generated code for auto-filling table at runtime:
    this.employeesTableAdapter.Fill(this.storageDataSet.employees);
}

2) 使用语句“|DataDirectory|” (不带引号)在您的助教的连接字符串中。在数据集设计器(架构)中选择 TA 并显示其属性。展开“连接”字段并选择不用于连接数据库的连接(VS2008 通常在将数据集绑定到 WinForms 控件时创建一个连接。如果没有,请手动为 TA 创建新连接)。因此,数据库连接的connectionString保持不变。
使用|数据目录|允许您使用数据库文件的相对路径,并且在大多数情况下与平台无关。对于我来说,这有帮助。希望,这也对您有帮助。

PS抱歉英语不好)

I spent a whole day in searching for solution to this problem.
Looks like it is a Visual Studio bug (I use VS2008Professional and had being stuck on this too).
Two possible actions in this case are:
1) Change the tableAdapter (TA) connectionString manually just before the TA had being constructed (before connection to db being opened in fact).

// something like this:
if (storageDataSetUtil.DesignerUtil.IsRunTime())
{
    // path to database file in my mobile device
    this.employeesTableAdapter.Connection.ConnectionString = @"/Program Files/MyApp/data/storage.s3db";

    // VS2008-generated code for auto-filling table at runtime:
    this.employeesTableAdapter.Fill(this.storageDataSet.employees);
}

2) Use statement '|DataDirectory|' (without quotes) in connectionString for your TA. In dataSet designer (schema) select TA and show its properties. Expand 'Connection' field and choose connection that you NOT use to connect to database (VS2008 usually creates one when you binding dataSet to WinForms controls. Create new connection for TA manually, if not). Thus, connectionString for database connection remains unchanged.
Using |DataDirectory| allows you to use relative paths to your DB file and being a platform-independent in most cases. As for me, this helps. Hope, this helps you too.

P.S. Sorry for poor English)

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