SQLiteException:无法打开数据库文件

时间:2010-09-29 18:39:50

标签: sqlite windows-mobile

我是Windows移动编程的新手,我正在尝试使用sqlite创建Windows Mobile 6应用程序。现在写我已经构建了一个虚拟测试应用程序,我尝试读取sqlite表的内容。

问题是我一直收到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?

1 个答案:

答案 0 :(得分:0)

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

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

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