1
我想在C#應用程序使用SQLite,但我有一個問題:使用C#中的SQLite連接
我遵循這個指南: http://blog.tigrangasparian.com/2012/02/09/getting-started-with-sqlite-in-c-part-one/
而且我的代碼是:
namespace MyDB
{
internal class SQLiteConnector_Local
{
private SQLiteConnection m_dbConnection;
public SQLiteConnector_Local() {
SQLiteConnection.CreateFile("MyDatabase.sqlite");
m_dbConnection = new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;");
m_dbConnection.Open();
SQLiteCommand command = new SQLiteCommand("CREATE TABLE IF NOT EXISTS singleOptions (key_column VARCHAR(50), value_column VARCHAR(80))", m_dbConnection);
command.ExecuteNonQuery();
m_dbConnection.Close();
}
}
}
我有個例外就行了:
m_dbConnection.Open();
除了離子是:
An exception of type 'System.AccessViolationException' occurred in System.Data.SQLite.dll but was not handled in user code.
是的,必須處理的例外,但我的主要問題是爲什麼我有這種例外?
我在其他問題中搜索瞭解決方案,但是我還沒有找到它。
已編輯。檢查路徑或嘗試指定絕對路徑 –
db是否正確的路徑?例如數據源= MyDatabase.sqlite-其中是MyDatabase.sqlite創建的? – DasDas
是的。使用CreateFile命令,該文件在可執行文件目錄中創建,並且我認爲該連接也嘗試在同一目錄中打開該文件。我嘗試了絕對路徑,但我有同樣的問題。 –