在SQLite中打开连接

Zai*_*Ali 2 c# sqlite windows-ce

我试图在Windows ce 5.1.17中使用SQLite.我在项目的debug文件夹中使用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
Run Code Online (Sandbox Code Playgroud)

此外,当我检查myConnection数据库属性时,它显示'Database ="main"'.我不知道为什么数据库名称是'main',但在myConnection中我将数据源设置为Stock.s3db.

zeF*_*chy 8

使用连接字符串构建器可确保获得格式正确的字符串

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();
Run Code Online (Sandbox Code Playgroud)