如何在不更改路径的情况下在另一台计算机上使用我的数据库?
我正在使用这条路径
SQLiteConnection conn = new SQLiteConnection(
"data source=C:\\Users\\users\\Documents\\Visual Studio 2012\\Projects\\SKM Computerized Payroll System\\db_SKMPayroll.sqlite");
最佳答案
不要使用您现在用于数据库文件的路径。它是用于存储开发中的 VS 项目的位置。部署应用程序时,不应使用任何开发文件夹。
你应该为你的数据库使用一个专用的文件夹,比如
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
或者你可以 use the folder your app is installed in ,前提是每个用户都具有读/写访问权限(它不应该例如在 ProgramFiles
中)
试试这个:
SQLiteConnection conn = new SQLiteConnection(
string.Format(
"data source={0}",
Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"db_SKMPayroll.sqlite"))
如果您使用存储在 \bin\Debug
或 \bin\Release
文件夹中的数据库文件 using CopyAllways , 请准备好 \bin\
文件夹中的开发数据库会被项目中的数据库文件覆盖。
关于sql - 在其他计算机上使用路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45901791/