0
尊重,SQLite 3和Odbc Data Srource名称
如何从c#连接sqlite数据库到Odbc连接字符串。我想通过数据srouce名称连接,所以我不想使用DB的绝对路径。我创建了带有Data Soruce Name“TestOdbc”的ODBC DSN,数据库名称是我的sqlite test.db的完整路径,位于C:\ Test \ test.db。在test.db中是一个包含少量记录的表格TestTable。
我尝试在c#和SqliteConnection中使用ODBCConnection,但我没有运气。使用SqliteConnection建立连接,但是连接没有建立到C:\ Test \ test.db我认为新数据库仅在:内存中创建,因为当我尝试从TestTable选择记录时出现表不存在的错误。
请任何sugesstion?
代码:
try
{
SQLiteConnection conn = new SQLiteConnection();
conn.ConnectionString = "Driver=SQLite3 ODBC Driver;Datasource=TestOdbc;";
conn.Open();
SQLiteCommand comm = new SQLiteCommand();
comm.Connection = conn;
comm.CommandText = "SELECT * FROM TestTable";
SQLiteDataReader created = comm.ExecuteReader();
comm.Dispose();
conn.Close();
Console.WriteLine("connection opened!!!");
}
catch(SQLiteException ex)
{
Console.WriteLine(ex.Message);
}
catch(InvalidOperationException ex)
{
Console.WriteLine(ex.Message);
}