从 MFC 应用程序连接到 SQL Server Compact Edition (.sdf) [英] Connecting to a SQL Server Compact Edition (.sdf) from an MFC application

查看:24
本文介绍了从 MFC 应用程序连接到 SQL Server Compact Edition (.sdf)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Visual Studio 2008 中构建一个 MFC 应用程序,它对纹理进行分类,我需要某种轻量级数据库来保存特征(只是一些双精度和字符串),它可以是:

I'm building an MFC app in Visual Studio 2008 which classifies textures and I need some sort of lightweight database to hold the characteristics (just some doubles and strings) which can be:

  • 在不同的电脑上随身携带该应用
  • 能够通过应用对其进行查询(搜索、更新、插入等)

目前我正在研究 SQL Server Compact Edition,因为它很容易从 Visual Studio 创建(我也只需要一个表).但是我很难从 C++ 连接和更新数据库.

Currently I'm looking into SQL Server Compact Edition because it was very easy to create from Visual Studio (I also need only one table). But I;m having a hard time connecting and updating the database from C++.

这是我在 MSDN 上找到的关于 C++ 和 SQLCE 的内容:

This is what I've found on MSDN regarding C++ and SQLCE:

public:
 void createSqlCeConnection(){
    SqlCeConnection* myConnection = new SqlCeConnection();
    myConnection->ConnectionString = "DataSource = blabla.sdf";
    MessageBox::Show(String::Format( S"Connection State: {0}", __box(myConnection->State)));
 }

不幸的是,我对 .NET 应用程序的体验非常有限.

Unfortunately my experience with .NET apps is pretty limited.

希望各位聪明人能告诉我我是否走在正确的道路上,以及我应该添加哪些链接和包含的内容才能与 C++ MFC 项目一起使用.

Hopefully you bright minds could tell me if I'm on the right path and what links and includes should I add for this to work with an C++ MFC projects.

推荐答案

对于 C++ 应用程序,您将需要使用 SQL CE 的 OLE DB 提供程序.例如,查看这里的代码片段 关于初始化会话(您可能必须显式单击示例部分中的 C++ 选项卡).

For C++ applications, you're going to want to use the OLE DB Provider for SQL CE. For example, take a look here for a code snippet on initializing a Session (you might have to explicitly click the C++ tab in the Examples section).

这篇关于从 MFC 应用程序连接到 SQL Server Compact Edition (.sdf)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆