You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Windows的Visual Studio 2017中用C++连接SQLite数据库的问题

Hey there, let's work through your two SQLite-related issues step by step—since you're new to Windows/C++ development, it's easy to mix up library versions and project configurations!

Fixing the VCRUNTIME140_APP.dll Missing Error

This error is the root of your runtime crash, and it's caused by a mismatch between the SQLite version you're using and your project type:

  • You downloaded the Universal Windows Platform (UWP) VSIX package of SQLite, which is built specifically for UWP apps (like those that run on Windows 10/11 devices via the Microsoft Store). UWP apps rely on a specialized version of the Visual C++ Runtime Library with the _APP suffix (hence VCRUNTIME140_APP.dll).
  • But your project is a standard Win32 console application (you're using main() as your entry point), which expects the regular desktop version of the VC Runtime (without the _APP suffix—VCRUNTIME140.dll instead).

Here's how to fix it:

  1. Download the correct SQLite binaries: Grab the Precompiled Binaries for Windows (x86/x64) from the SQLite download page (not the UWP VSIX). This package is designed for desktop applications like your console program.
  2. Replace your current SQLite files: Swap out the UWP version of sqlite3.h, sqlite3.lib, and sqlite3.dll with the desktop versions from the new download.
  3. Update your project configuration:
    • In Visual Studio 2017, right-click your project → Properties → Configuration Properties → C/C++ → Code Generation.
    • Set the Runtime Library option to match the SQLite build (use /MD for release builds, /MDd for debug builds—this aligns with the precompiled desktop binaries).
  4. Place the DLL in the right location: Copy sqlite3.dll to your project's output directory (e.g., Debug/x86 or Release/x86) instead of just the project root. This ensures your executable can find it at runtime.

Understanding the x64 Compilation Error with SQLite

The compile error you saw when using the x64 UWP SQLite library ties back to the same project type mismatch:

  • The UWP SQLite headers and libraries include UWP-specific macros, definitions, and dependencies that your Win32 console project doesn't support. For x86, you might have avoided immediate errors by chance, but the underlying mismatch still exists (which is why you hit the runtime DLL error).
  • When you switch to the desktop version of SQLite's x64 binaries, you'll be able to compile your project for x64 without issues—just repeat the configuration steps above for the x64 platform.

Quick Code Improvement

Also, let's tweak your code to handle database cleanup safely, especially when opening fails:

#include "stdafx.h"
#include "sqlite3.h"
int main() {
    sqlite3* db = nullptr;
    int rc = sqlite3_open("test.db", &db); // Replace with your actual DB path (use double backslashes for absolute paths, e.g., "C:\\Users\\YourName\\test.db")
    
    if (rc != SQLITE_OK) {
        printf("ERROR: can't open database: %s\n", sqlite3_errmsg(db));
        // Only close the DB handle if it was initialized
        if (db) {
            sqlite3_close(db);
        }
    } else {
        printf("Connection Successful");
        sqlite3_close(db);
    }
    
    return 0;
}

内容的提问来源于stack exchange,提问作者Ponysopher

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:14:51