c# - 在 SQLite 中打开连接

标签 c# sqlite windows-ce

我正在尝试在 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/

相关文章:

c# - 日期格式模式

c# - OpenID 连接与 ASP.NET MVC

android - Android 库项目可以有自己的 SQLite 数据库吗?

node.js - Promise 返回未定义和之后的数据

Windows CE 5 中的 C# 应用程序最终崩溃

c++ - sqlite3中使用汉字

windows-ce - 为非 x86 目标自定义引导加载程序闪屏

c# - 检测正在打印的页面百分比(页面覆盖率)

c# - WPF 中线程的一个非常基本的解释?

android - 什么 sqlite db 查询获取具有特定字符串 id 的最后一行记录