views:

31

answers:

2

Hello,

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();  
                while (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?

Thanks in advance

A: 

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;")
ctacke
thanks for clarifying - does he need New=true in the connection string?
SB
A: 

Thank you,

I did that and it managed to connect. Though, I get another error now.

SQLite error no such table: MyTable

I would appreciate some help please... Can anyone explain why is that happening?

Or give me a clue where to search for it?

Thanks

vesta
There isn't a table in your database named MyTable?
BenW
Just to add, you probably need to add the database your connecting to in the string (the initial catalog) not just the data source.
BenW
There is a Table named MyTable there. When I run it I see that database is main and not the database myfirsttest. I'm missing some parts of the puzzle...
vesta
My last comment just clarified that, you need to specify which database to connect to, you have said where the data bases are (the data source) but its possible to have many different databases on the data source.. hence setting the 'initial catalog' property in the connection string.. google sql lite connection strings
BenW
Nothing works :S Does anyone know where I can find a sample project?
vesta