I am developing C#-based mobile application and the exception always thrown and catched by my try catch block
Exceptin thrown : The database file cannot be found.Check the path to the database [File name = .\MyMobileDB.sdf]

the snippet code is

namespace DeviceApplication4
{
    public partial class Form1 : Form
    {
        public string strCon = @"Data Source =.\MyMobilePhoneDB.sdf; Password =123@asu";
        public SqlCeConnection SqlConn;
        public SqlCeCommand CeCmd = new SqlCeCommand();
        public SqlCeDataReader dataReader;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                SqlConn = new SqlCeConnection(strCon);
                CeCmd.CommandText = strCon;
                SqlConn.ConnectionString = strCon;

                MessageBox.Show("After open");

                SqlConn.Open();


                MessageBox.Show("After open");
                

                SqlConn.Close();

                MessageBox.Show("After close");
            }
            catch (SqlCeException x)
            {
                MessageBox.Show( x.ToString());

            }
        }
    }
}

This exception exception thrown at line 27 and displayed after being caught at line 36

Recommended Answers

All 2 Replies

>DB file cannot be found chck the path to the DB

Use absolute path.

public string strCon = @"Data Source =x:\folder\MyMobilePhoneDB.sdf; Password =123@asu";

>DB file cannot be found chck the path to the DB

Use absolute path.

public string strCon = @"Data Source =x:\folder\MyMobilePhoneDB.sdf; Password =123@asu";

Thank you for all of you you are so gentl
I solved the problem to have a database on my device application
and this the way

step 1 : Create New database represents the database of my project
A- R-click on the project (not solution explorer)
B- Add new item
C-Choose Database file

Step 2 : from the Menue bar : Data -> Create new Data Source
following the wizard you can add the the file created in previous step as the new data Source

step 3 : from the Menue : Data -> ShowDataSource
a DataSet will appear on the left panel , R-click on it and choose
Edit DataSet with Designer

Step 4 : Add a dataTable for each column
Simply Right click on the DataSet Designer , and add required relations
Step 5 : Please see the following link and thank you in advance

http://www.codeproject.com/KB/mobile...px?msg=3296512

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.