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

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

问题描述

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




  • 在不同的计算机上执行应用程序

  • 能够从应用程序执行查询(搜索,更新,插入等)



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



这是我在MSDN上发现的关于C ++和SQLCE的



  public:
void createSqlCeConnection(){
SqlCeConnection * myConnection = new SqlCeConnection();
myConnection-> ConnectionString =DataSource = blabla.sdf;
MessageBox :: Show(String :: Format(SConnection State:{0},__box(myConnection-> State)));不幸的是,我使用.NET应用程序的经验是相当有限的。



希望你聪明的头脑可以告诉我,如果我在正确的路径,我应该添加什么链接和包括这个使用C ++ MFC项目。 p>

解决方案

对于C ++应用程序,您将要使用 SQL CE的OLE DB提供程序。例如,查看此处的代码段(您可能必须显式单击示例部分中的C ++选项卡)。


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:

  • Carried around with the app on different computers
  • Be able to perform queries on it from the app (searches , updates ,inserts ,etc)

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++.

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)));
 }

Unfortunately my experience with .NET apps is pretty limited.

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.

解决方案

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精简版(.sdf)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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