如何在Windows上使用Visual Studio 2017连接到C++中的SQLite数据库? 对于Windows开发和C++,我是相当新的。在尝试连接到sqlite数据库时,我编写了以下代码段 #include "stdafx.h" #include "sqlite3.h" int main() { sqlite3* db; if (sqlite3_open(<path to db>, &db) != SQLITE_OK) { printf("ERROR: can't open database: %s\n", sqlite3_errmsg(db)); } else { printf("Connection Successful"); } sqlite3_close(db); return 0; }
我从下载了通用Windows平台VSIX包,其中包括一个sqlite3.lib文件和一个sqlite3.dll。在Microsoft Visual Studio 2017中,我包含了sqlite3.lib文件和目录,并将sqlite3.dll复制到项目目录中 我应该注意,包含的sqlite3.lib是x86版本。尝试包含x64版本会导致“include sqlite3.h”语句出现生成错误。我想知道为什么会这样,但我现在可以接受32位 按原样运行代码会在运行时产生以下错误:无法继续执行代码,因为找不到VCRUNTIME140_APP.dll如何在Windows上使用Visual Studio 2017连接到C++中的SQLite数据库? 对于Windows开发和C++,我是相当新的。在尝试连接到sqlite数据库时,我编写了以下代码段 #include "stdafx.h" #include "sqlite3.h" int main() { sqlite3* db; if (sqlite3_open(<path to db>, &db) != SQLITE_OK) { printf("ERROR: can't open database: %s\n", sqlite3_errmsg(db)); } else { printf("Connection Successful"); } sqlite3_close(db); return 0; },c++,dll,sqlite,visual-studio-2017,visual-c++,C++,Dll,Sqlite,Visual Studio 2017,Visual C++,我从下载了通用Windows平台VSIX包,其中包括一个sqlite3.lib文件和一个sqlite3.dll。在Microsoft Visual Studio 2017中,我包含了sqlite3.lib文件和目录,并将sqlite3.dll复制到项目目录中 我应该注意,包含的sqlite3.lib是x86版本。尝试包含x64版本会导致“include sqlite3.h”语句出现生成错误。我想知道为什么会这样,但我现在可以接受32位 按原样运行代码会在运行时产生以下错误:无法继续执行代码,因为
建议安装visual studio时应包含dll。上述dll文件确实存在于C:\Program Files x86中的多个位置,包括.lib文件所在的Microsoft SDK文件夹。为什么找不到它?SQLite将在msvc下编译,不会有任何麻烦。因此,您可以在msvc中直接将sqlite3.h和sqlite3.cpp包含到您的项目中,并避免将其用作依赖项库。SQLite将在msvc下轻松编译。因此,您可以直接将SqLeI3.0.h和SqLeE3.CPP包含到MSVC中的项目中,避免使用AS依赖库。< P>下载并复制以下文件夹到VisualC++解决方案文件夹。 sqlite3文件夹包含x86和x64版本的sqlite dll和lib。 您可以升级到sqlite.dll的最新版本。 下载并复制下列文件到VisualC++项目文件夹中,为它们添加引用。 下面是查询数据库的示例代码
#include "CppSQLite3.h"
#include <iostream>
#include <string>
using namespace std;
CppSQLite3DB db;
bool GetDatabase(const string& dbPath)
{
try {
db.open(dbPath.c_str());
return true;
}
catch (CppSQLite3Exception& e)
{
cout << _T("Cannot open database: ") << dbPath << _T("\n");
return false;
}
}
void IssueQuery(const string& querystring, const string& field1)
{
try {
CppSQLite3Query q = db.execQuery(querystring.c_str());
while (!q.eof()) {
CString temp2(q.fieldValue(field1.c_str()));
TRACE(temp2 + _T("\n"));
q.nextRow();
}
}
catch (CppSQLite3Exception& e)
{
cout << _T("Cannot execute query: ") << querystring << _T("\n");
}
}
void main()
{
if(GetDatabase("C:\\test.sqlite"))
IssueQuery("SELECT * FROM DUAL", "X");
}
下载并复制以下文件夹到VisualC++解决方案文件夹中。 sqlite3文件夹包含x86和x64版本的sqlite dll和lib。 您可以升级到sqlite.dll的最新版本。 下载并复制下列文件到VisualC++项目文件夹中,为它们添加引用。
下面是查询数据库的示例代码#include "CppSQLite3.h"
#include <iostream>
#include <string>
using namespace std;
CppSQLite3DB db;
bool GetDatabase(const string& dbPath)
{
try {
db.open(dbPath.c_str());
return true;
}
catch (CppSQLite3Exception& e)
{
cout << _T("Cannot open database: ") << dbPath << _T("\n");
return false;
}
}
void IssueQuery(const string& querystring, const string& field1)
{
try {
CppSQLite3Query q = db.execQuery(querystring.c_str());
while (!q.eof()) {
CString temp2(q.fieldValue(field1.c_str()));
TRACE(temp2 + _T("\n"));
q.nextRow();
}
}
catch (CppSQLite3Exception& e)
{
cout << _T("Cannot execute query: ") << querystring << _T("\n");
}
}
void main()
{
if(GetDatabase("C:\\test.sqlite"))
IssueQuery("SELECT * FROM DUAL", "X");
}
您是否使用MSVS项目向导创建Windows应用商店应用程序通用应用程序或标准Win32控制台应用程序?你不能混搭。这可能就是问题所在,谢谢。我会检查其他下载是否有效。@RichardCriten:您可以在常规桌面应用程序中使用绝大多数通用Windows平台API。除了少数例外,您可以混合和匹配。您是否使用MSVS项目向导创建了Windows应用商店应用程序通用应用程序或标准Win32控制台应用程序?你不能混搭。这可能就是问题所在,谢谢。我会检查其他下载是否有效。@RichardCriten:您可以在常规桌面应用程序中使用绝大多数通用Windows平台API。除了少数例外,你可以混搭。