2010-09-29 54 views
0

我是新来的Windows移动编程,我试图创建一个使用SQLite的Windows Mobile 6应用程序。现在写入我已经构建了一个虚拟测试应用程序,我尝试读取sqlite表的内容。SQLiteException:无法打开数据库文件

问题是我一直收到SQLiteException:无法打开数据库文件。

我的代码如下:

using (var cn = new SQLiteConnection(@"Data Source=C:myfirsttest.s3db;")) 
     { 
      try 
      { 
       //Connect to SQLite database 
       cn.Open(); 

       //Create the SQL Command 
       var cmd = new SQLiteCommand(); 
       cmd.Connection = cn; 
       cmd.CommandText = "SELECT * FROM MyTable"; 

       //Retrieve the records using SQLiteDataReader 
       var dr = cmd.ExecuteReader(); 
       while (dr.Read()) 
       { 
        //display records 
        var id = dr["ID"].ToString(); 
       } 

      } 
      catch(Exception ex) 
      { 

       //display any exeptions 
       var except = ex.Message; 
      } 
      finally 
      { 
       cn.Close(); 
      } 
     } 

谁能帮我请了吗?或者建议一个教程,我可以找到如何在Windows Mobile 6项目中设置sqlite?

回答

0

Windows CE(WinMo的基本操作系统)没有驱动器,也没有工作文件夹的概念。这意味着所有路径必须完全合格。你可能想是这样的:

new SQLiteConnection(@"Data Source=\myfirsttest.s3db;") 

new SQLiteConnection(@"Data Source=\[my app path]\myfirsttest.s3db;") 
+0

感谢澄清 - 他需要新=连接字符串中真的吗? – 2010-09-29 19:53:06

相关问题