小编B M*_*ter的帖子

通过网络连接到 SQLite 数据库

我当前正在映射网络驱动器并以这种方式连接到文件 (Z:\Data\Database.db)。我希望能够在连接字符串中使用相对路径 (\server\Data\Database.db),但它给了我一个 SQLite 错误“无法打开数据库文件”。检查Directory.Exists(\\server\Data\Database.db);返回 true。

以下是使用路径“\\server”作为参数打开连接的尝试:

public static OpenDB(string dbPath)
{
    using (SQLiteConnection conn = new SQLiteConnection($"Data Source={Path.Combine(dbPath, "Data\\Database.db")}"))
    {
        if (dbPath != null && dbPath != "")
        {
            try
            {
                conn.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Unable to Open Database", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# sqlite sqlconnection

5
推荐指数
1
解决办法
1328
查看次数

标签 统计

c# ×1

sqlconnection ×1

sqlite ×1