SQLite + C#:无法打开数据库文件 [英] Sqlite + c#: Unable to open the database file

查看:139
本文介绍了SQLite + C#:无法打开数据库文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void SetConnection()
{
     string a = string.Format(@"Data Source={0};Version=3;New=False;Compress=True;", "~/lodeDb.db");
     sql_con = new SQLiteConnection(a);
}

private void ExecuteQuery(string txtQuery)
{
     SetConnection();
     sql_con.Open();
     sql_cmd = sql_con.CreateCommand();
     sql_cmd.CommandText = txtQuery;
     sql_cmd.ExecuteNonQuery();
     sql_con.Close();
}

当我运行sql_cmd.ExecuteNonQuery时,Sqlexception是无法打开数据库文件。我的在线托管上的 lodeDb.db文件,我认为数据源错误。您能告诉我在线托管中是否有db文件吗?如何设置用于连接的数据源
谢谢
注意:权限文件在这里没问题

When i run to sql_cmd.ExecuteNonQuery, Sqlexception is "Unable to open the database file". "lodeDb.db" file on my online hosting, i think data source is wrong. Can U tell me if db file in online hosting. How to set datasourse for connection Thanks you Note: Permission file is no problem in here

推荐答案

尝试打开网络驱动器上的数据库时,我遇到了同样的异常(路径以 \\myServer\myDbFile ...开头),我通过输入 true 到连接构造函数中的 parseViaFramework 参数。

I got the same exception when trying to open databases that are on the network drive (path starts with "\\myServer\myDbFile...") and I resolved it by putting true to the parseViaFramework parameter in connection constructor.

sql_con = new SQLiteConnection(a, true);

这篇关于SQLite + C#:无法打开数据库文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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