Connecting to a SQL Server Compact Edition (.sdf) from an MFC application

孤街浪徒 提交于 2019-12-04 03:46:25

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/2760879/connecting-to-a-sql-server-compact-edition-sdf-from-an-mfc-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!