2009-09-22 155 views
0

我有在C我的C#应用​​程序:\ Program Files文件\程序\文件夹 我使用sqllite数据库无法打开数据库

我的代码完美的工作,同时通过Windows管理员用户登录时,如果我改变窗口的用户帐户有限,我无法打开我的数据库

public void OpenDB() 
{ 
SQConnectionString = "Data Source=" + DBPath +";Pooling=true;FailIfMissing=false"; 
con = new SQLiteConnection(); 
con.ConnectionString = SQConnectionString; 
con.Open(); 
} 
+0

什么是错误消息? – 2009-09-22 11:59:23

+0

检查数据库文件的权限? – Lazarus 2009-09-22 12:01:47

回答

2

Program Files文件目录绝对不是把数据在正确的地方......在Windows Vista和七,此目录的写入权限除非应用程序以管理员身份运行,否则无法写入。您应该将数据库置于ProgramData或用户的数据目录中。您可以使用Environment.GetFolderPath方法获取这些目录:

string userAppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); 
// On Vista and Seven, this is C:\Users\<username>\AppData\Roaming 
// On XP, this is C:\Documents and Settings\<username>\Application Data 

string commonAppData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); 
// On Vista and Seven, this is C:\ProgramData 
// On XP, this is C:\Documents and Settings\All Users\Application Data 
+0

感谢您的快速响应 – 2009-09-23 06:36:34

0

是否非管理员用户有权限write对您安装的SQLite的目录?因为如果您正在使用日志文件,可能会发生这种情况。

0

这是因为非管理员用户不具有对program files文件夹