我正在尝试在 Windows ce 5.1.17 中使用 SQLite。 我使用 SQLite Administrator 创建了一个 SQLite 数据库在我项目的调试文件夹中。 然后我将 System.Data.SQLite.dll 和 SQLite.Interop.065.dll 添加到我的项目中。 我正在尝试使用以下代码连接到数据库。
SQLiteConnection myConnection = null;
myConnection = new SQLiteConnection(@"Data Source=" + System.IO.Path.Combine(System.IO.Path. GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase), Stock.s3db)+ "; Version=3; Cache Size =100");
myConnection.Open();
SQLiteCommand cmd = new SQLiteCommand();
cmd.CommandText = "select * from shops;";
cmd.CommandType = CommandType.Text;
cmd.Connection = myConnection;
cmd.ExecuteReader();// I get exception no such table: shops
此外,当我检查 myConnection 数据库属性时,它显示“Database = “main””。我不知道为什么数据库名称是“main”,但在 myConnection 中我将数据源设置为 Stock.s3db。
最佳答案
使用连接字符串生成器确保您获得格式正确的字符串
SQLiteConnectionStringBuilder builder = new SQLiteConnectionStringBuilder();
builder.FailIfMissing = true;
builder.DataSource = "Insert the fully qualified path to your sqlite db";
SQLiteConnection connection = new SQLiteConnection(builder.ConnectionString);
connection.Open();
关于c# - 在 SQLite 中打开连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7499269/