开发者

SQLiteException: Unable to open the database file

I'm new to windows mobile programming and I'm trying to create a Windows Mobile 6 application using sqlite. Write now I have built a dummy test application where I try to read the contents of a an sqlite table.

The problem is that I keep receiving SQLiteException: Unable to open the database file.

My code is below:

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();  
                whil开发者_JS百科e (dr.Read())  
                {  
                    //display records  
                    var id = dr["ID"].ToString();  
                }  

            }  
            catch(Exception ex)  
            {  

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

Can anyone help me please with that? Or suggest a tutorial where I can find how to setup sqlite in a windows mobile 6 project?


Windows CE (the base OS for WinMo) does not have drives nor does it have a concept of a working folder. This means that all paths must be fully qualified. You probably want something like:

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

or

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜