SQLite:即使以前工作过,也无法以编程方式打开网络文件 [英] SQLite: Cannot open network file programmatically, even though worked before
问题描述
我几乎每天都使用下面的代码打开一个 SQLite 数据库文件,该文件位于网络计算机上一年多.今天早上突然,我无法以编程方式打开文件.
I have used the code below to open a SQLite database file that sits on a network computer for more than a year now almost on a daily basis. Suddenly this morning, I am not able to open the file programmatically.
private Boolean Connect(String strPathFile)
{
// Initialize the connection object.
this.DbConnection = null;
try
{
// DATABASE: Create the connection string and set the settings.
String strConnection = @"Data Source=" + strPathFile + @";Version=3;";
// DATABASE: Connect to the database.
this.DbConnection = new SQLiteConnection(strConnection);
this.DbConnection.Open();
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return false;
}
该文件是格式为\Server\ShareName\FileName.db"(减去双引号)的网络资源.
The file is a network resource in the form "\Server\ShareName\FileName.db" (less the double quotes).
这里是有趣的事情.SQLite 管理员在打开网络数据库文件时没有问题,没有问题,而且反复出现.我也可以在本地打开文件.我将文件复制到本地驱动器,然后简单地更改了 Visual Studio 2012 (VS2012) 中的路径.
Here is the interesting thing. SQLite Administrator has no issues opening up the network database file, none, and repeatedly. I can also open up the file locally. I copied the file to my local drive and simply changed the path inside Visual Studio 2012 (VS2012).
服务器看起来不错.自从我上次检查它以来,它在某个时候经历了重新启动.我假设是 Microsoft 更新.文件资源管理器浏览文件夹没有问题,正如我所说,SQLite 管理员可以打开网络文件.
The server seemed fine. It had gone through a reboot at some point since the last time that I checked on it. I presume a Microsoft Update. File Explorer has no issues browsing the folder, and as I said SQLite Administrator can open the network file.
我再次检查了权限,每个人都拥有完全控制权,服务器的用户也拥有完全控制权,包括安全权限和共享权限.我检查了文件夹和文件,权限是一样的.我期望的一样多,因为 SQLite 管理员可以打开该文件.服务器没有设置防火墙、Windows 防火墙或其他方式.我今天早上也重新检查过.同样,SQLite 管理员会抱怨这个.
I checked once again on permissions and everyone has full control as well as the server's users have full control, both on the security permissions and on the share permissions. I checked the folder and file, and permissions are the same. I expected as much, because SQLite Administrator can open the file. The server does not have a firewall set up, Windows Firewall or otherwise. I rechecked that this morning as well. Again, SQLite Administrator would have complained about that.
我通过使用文件资源管理器在网络驱动器上复制文件来验证写入.那没有问题.
I verified writing, by making a copy of the file on the network drive using File Explorer. That had no issues.
服务器是 Windows Server 2003.我使用的是 Windows 7 Professional 64 位.
The sever is a Windows Server 2003. I am using Windows 7 Professional 64-bit.
我也尝试以只读模式打开数据库,但也失败了.我期待这种行为.SQLite 管理员仍然运行良好.
I also tried to open up the database in read only mode, but that failed as well. I was expecting that behavior. SQLite Administrator still works nicely.
我尝试了各种其他的连接字符串,包括 SQLiteConnectionStringBuilder() 只是为了看看会发生什么,条条大路通罗马,即:
I tried various other connection strings including SQLiteConnectionStringBuilder() just to see what happens, and all roads lead to Rome, namely:
System.Data.SQLite.SQLiteException occurred
HResult=-2147467259
Message=unable to open database file
Source=System.Data.SQLite
ErrorCode=14
StackTrace:
at System.Data.SQLite.SQLite3.Open(String strFilename, SQLiteConnectionFlags connectionFlags, SQLiteOpenFlagsEnum openFlags, Int32 maxPoolSize, Boolean usePool)
at System.Data.SQLite.SQLiteConnection.Open()
at SQL.cSQL.Connect(String strPathFile) in C:\<Path to source file>:line 367
InnerException:
想法?
推荐答案
in version > 1.0.82.0
in version > 1.0.82.0
将文件名中的前两个反斜杠加倍(例如
"\\\\network\share\file.db"
).
使用映射的驱动器号.
使用采用 parseViaFramework 的 SQLiteConnection 构造函数布尔参数并为该参数传递true".
Use the SQLiteConnection constructor that takes the parseViaFramework boolean argument and pass 'true' for that argument.
查看 SQL 帖子这里
这篇关于SQLite:即使以前工作过,也无法以编程方式打开网络文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!