我的數據庫位於所述應用程序文件夾 實施例以外:如何在C#中指定一個相對的SQLite數據庫路徑?
數據庫:SampleApplication\Database\Database.sqlite
應用:SampleApplication\Application\program.cs
我的代碼如下所示。
string relativePath = @"SampleApplication\Database\Database.sqlite";
string currentPath;
string absolutePath;
string connectionString;
currentPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
absolutePath = Path.Combine(currentPath, relativePath);
connectionString = string.Format("Data Source={0};Version=3;Pooling=True;Max Pool Size=100;", absolutePath);
m_dbConnection = new SQLiteConnection(connectionString);
m_dbConnection.Open();
嘗試VAR路徑= @「數據源= ./Database/Database.sqlite 「; –
@Keshav檢查我的回答 –