locked
DataAccess Problem in Windows Mobille RRS feed

  • Question

  • Hello All,

    I am trying my hand on dealing with database in windows mobile application. I am following below link :

    http://www.codeproject.com/KB/windows/SampleMobileApplication.aspx

    I am getting error :  The path is not valid.Check the directory for the database.

    I have checked the path for the database through ActiveSync , the database is there on the path, still error is coming...please help to solve the problem.

     

    Thanks in advance.

     

     

    Thursday, October 20, 2011 5:23 AM

All replies

  • Hi,

    Check the below links to solve your problem

    1)http://social.msdn.microsoft.com/Forums/en-US/sqlce/thread/3cf44321-ff1e-4903-ac2f-570f8759055a/

    2)http://social.msdn.microsoft.com/Forums/en-US/vssmartdevicesvbcs/thread/0f32993e-5b16-43b4-b7b6-09a3f66eb2f2/

    3)http://stackoverflow.com/questions/3448036/where-to-place-my-sdf-file-when-testing-application-through-emulator


    PS.Shakeer Hussain
    Thursday, October 20, 2011 5:32 AM
  • hey thanks for reply,

    I go through all three and i tried the way said by ashraf fawzy on this

    http://social.msdn.microsoft.com/Forums/en-US/vssmartdevicesvbcs/thread/0f32993e-5b16-43b4-b7b6-09a3f66eb2f2/

    Link but still not getting connected to database , any other suggestion ?

     

    Thursday, October 20, 2011 7:33 AM
  • Hi,

    Post your Code to understand.


    PS.Shakeer Hussain
    Thursday, October 20, 2011 7:46 AM

  • Here it is :

     

     private void GetTableData()
            {
                SqlCeConnection conn = null;
                try
                {
                   // conn = new SqlCeConnection("Data Source = \\Program Files\\SampleDatabase\\Database1.sdf;");
                    string str =  GetExePath() + "\\Database1.sdf";
                    conn = new SqlCeConnection(str);
                    conn.Open();
                    SqlCeCommand cmd = conn.CreateCommand();
                    SqlCeDataAdapter dAdp = new SqlCeDataAdapter();
                    DataSet ds = new DataSet();
                    cmd.CommandText = "SELECT * FROM EMP";
                    dAdp.SelectCommand = cmd;
                    cmd.ExecuteReader();
                    dAdp.Fill(ds);
                    dgEmp.DataSource = ds.Tables[0];
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    conn.Close();
                }
            }

            private string GetExePath()
            {
                return System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
            }

    Thursday, October 20, 2011 7:49 AM