當應用程式在 Windows 啟動時啟動時出現此錯誤,但是當我在 Windows 運行時打開它時應用程式運行完美。
SQLite error (14): cannot open file at line 47640 of [b0c4230c89]
Exception thrown: 'System.Data.SQLite.SQLiteException' in System.Data.SQLite.dll
SQLite error (14): os_win.c:47639: (2) winOpen(C:\WINDOWS\System32\qubanga.db) - The system cannot find the file specified
這是程式用來檢索資料庫的 sqlite 資料庫連接。
try
{
SQLiteConnection sqlite_conn = new SQLiteConnection("Data Source=database.db; Version = 3; New = True; Compress = True; ");
sqlite_conn.Open();
SQLiteCommand sqlite_cmd;
string createTable = "Insert into " table "(" columns ") Values(" values ");";
sqlite_cmd = sqlite_conn.CreateCommand();
sqlite_cmd.CommandText = createTable;
var query = sqlite_cmd.ExecuteNonQuery();
if (query == 1)
result = true;
}
為程式設定啟動
public static void SetStartup()
{
RegistryKey rk = Registry.CurrentUser.OpenSubKey
("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
rk.SetValue("AppName", Application.ExecutablePath);
}
uj5u.com熱心網友回復:
如果您的應用程式與 System32 檔案夾(我希望它是)位于不同的檔案夾中,您的代碼會將注冊表項設定為該檔案夾路徑。運行 regedit 并導航到該鍵進行檢查。因此,在啟動時,Windows 將查找 db 的 Application 檔案夾,而不是 System32 檔案夾。嘗試將其設定為 System32 檔案夾。
rk.SetValue("AppName", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "qubanga.db" );
uj5u.com熱心網友回復:
因此,在使用上面提供的解決方案解決問題之后,我意識到 Windows 啟動時的程式是從C:\WINDOWS\System32\它的安裝位置而不是它的安裝位置執行的。我通過更改應用程式的作業目錄解決了這些問題。我從@Caius 得到了這個想法
public static void SetWorkingDirectory()
{
string excePath = AppDomain.CurrentDomain.BaseDirectory;
Directory.SetCurrentDirectory(excePath);
//Console.WriteLine(Directory.GetCurrentDirectory());
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/420112.html
標籤:
