2009-09-22 152 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文件夾