Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Mobile
  4. SQLCE Connection Problems

SQLCE Connection Problems

Scheduled Pinned Locked Moved Mobile
databasealgorithmsquestion
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vafo
    wrote on last edited by
    #1

    Hello! I am facing some problems on the development of my mobile simlpe application connecting to an SQLCE database. After searching a bunch of sites, tutorials and Q&A's my code seems to be correct and I can't figure out what's going wrong. This is my code:

                SqlCeConnection conn = new SqlCeConnection("Data Source=ChokweDB.sdf");
                SqlCeCommand insertForm1 = new SqlCeCommand("INSERT INTO Form1Table (p1,p2,p3,p4,entrevistador,data) values ('" + p1.Text + "','" + p2.Text + "','" + p3Value + "','" + p4Value + "','" + txtEntrevistador.Text + "','" + txtData.Text + "')", conn);
                conn.Open();
                insertForm1.ExecuteNonQuery();
                conn.Close();
    

    My database is placed in the home directory of the application (filename ChokweDB.sdf). When I run the code, MVS2008 will simply not find the database:

    The database file cannot be found. Check the path to the database. [ Data Source = ChokweDB.sdf ]

    Why oh why? What am I missing?

    P K J 3 Replies Last reply
    0
    • V vafo

      Hello! I am facing some problems on the development of my mobile simlpe application connecting to an SQLCE database. After searching a bunch of sites, tutorials and Q&A's my code seems to be correct and I can't figure out what's going wrong. This is my code:

                  SqlCeConnection conn = new SqlCeConnection("Data Source=ChokweDB.sdf");
                  SqlCeCommand insertForm1 = new SqlCeCommand("INSERT INTO Form1Table (p1,p2,p3,p4,entrevistador,data) values ('" + p1.Text + "','" + p2.Text + "','" + p3Value + "','" + p4Value + "','" + txtEntrevistador.Text + "','" + txtData.Text + "')", conn);
                  conn.Open();
                  insertForm1.ExecuteNonQuery();
                  conn.Close();
      

      My database is placed in the home directory of the application (filename ChokweDB.sdf). When I run the code, MVS2008 will simply not find the database:

      The database file cannot be found. Check the path to the database. [ Data Source = ChokweDB.sdf ]

      Why oh why? What am I missing?

      P Offline
      P Offline
      PavanPareta
      wrote on last edited by
      #2

      Hi Vafo, in your code you have to specify exact database path. string DBPath = @"Program Files\ChokweDB.sdf"; SqlCeConnection conn = new SqlCeConnection("Data Source=" + DBPath ); hope this will help you...

      Pavan Pareta

      modified on Friday, April 24, 2009 2:47 PM

      V 1 Reply Last reply
      0
      • P PavanPareta

        Hi Vafo, in your code you have to specify exact database path. string DBPath = @"Program Files\ChokweDB.sdf"; SqlCeConnection conn = new SqlCeConnection("Data Source=" + DBPath ); hope this will help you...

        Pavan Pareta

        modified on Friday, April 24, 2009 2:47 PM

        V Offline
        V Offline
        vafo
        wrote on last edited by
        #3

        Can't build, unrecogized escape sequence error after each dash...seen this before..

                    string dbconn = "@C:\\Documents and Settings\\Vasco\\Ambiente de trabalho\\Serviços de Informática\\ChokweMobile\\ChokweDB.sdf";
                    SqlCeConnection conn = new SqlCeConnection("Data Source=" + dbconn);
        

        And after some correcting... <pre> string dbconn = @"C:\Documents and Settings\Vasco\Ambiente de trabalho\Serviços de Informática\ChokweMobile\ChokweDB.sdf"; SqlCeConnection conn = new SqlCeConnection("Data Source=" + dbconn); Returns Path not valid. And...

        string dbconn = @".\ChokweDB.sdf";

        The database file cannot be found. Check the path to the database. [ Data Source = .\ChokweDB.sdf ] The database IS o the same folder as the application - and it really IS there and the name is spelled correctly..

        modified on Thursday, April 23, 2009 7:10 AM

        1 Reply Last reply
        0
        • V vafo

          Hello! I am facing some problems on the development of my mobile simlpe application connecting to an SQLCE database. After searching a bunch of sites, tutorials and Q&A's my code seems to be correct and I can't figure out what's going wrong. This is my code:

                      SqlCeConnection conn = new SqlCeConnection("Data Source=ChokweDB.sdf");
                      SqlCeCommand insertForm1 = new SqlCeCommand("INSERT INTO Form1Table (p1,p2,p3,p4,entrevistador,data) values ('" + p1.Text + "','" + p2.Text + "','" + p3Value + "','" + p4Value + "','" + txtEntrevistador.Text + "','" + txtData.Text + "')", conn);
                      conn.Open();
                      insertForm1.ExecuteNonQuery();
                      conn.Close();
          

          My database is placed in the home directory of the application (filename ChokweDB.sdf). When I run the code, MVS2008 will simply not find the database:

          The database file cannot be found. Check the path to the database. [ Data Source = ChokweDB.sdf ]

          Why oh why? What am I missing?

          K Offline
          K Offline
          Khatri Mitesh
          wrote on last edited by
          #4

          Hi, Add data source in your project. then select your database (.sdf) file in your solution. then click properties then set the value of Copy to Output Directory = Copy Always. Try this. Thanks

          ~Khatri Mitesh khatrimitesh@hotmail.com Bikaner (Rajasthan) INDIA http://www.youtube.com/watch?v=-oJaaPCrk3Q

          1 Reply Last reply
          0
          • V vafo

            Hello! I am facing some problems on the development of my mobile simlpe application connecting to an SQLCE database. After searching a bunch of sites, tutorials and Q&A's my code seems to be correct and I can't figure out what's going wrong. This is my code:

                        SqlCeConnection conn = new SqlCeConnection("Data Source=ChokweDB.sdf");
                        SqlCeCommand insertForm1 = new SqlCeCommand("INSERT INTO Form1Table (p1,p2,p3,p4,entrevistador,data) values ('" + p1.Text + "','" + p2.Text + "','" + p3Value + "','" + p4Value + "','" + txtEntrevistador.Text + "','" + txtData.Text + "')", conn);
                        conn.Open();
                        insertForm1.ExecuteNonQuery();
                        conn.Close();
            

            My database is placed in the home directory of the application (filename ChokweDB.sdf). When I run the code, MVS2008 will simply not find the database:

            The database file cannot be found. Check the path to the database. [ Data Source = ChokweDB.sdf ]

            Why oh why? What am I missing?

            J Offline
            J Offline
            Jabbar_espania
            wrote on last edited by
            #5

            you should to add the data base trough add elements there you can see your data base and can execute program to compile if you want to compile trough mobile device add the data base in mobile device Thanks

            D 1 Reply Last reply
            0
            • J Jabbar_espania

              you should to add the data base trough add elements there you can see your data base and can execute program to compile if you want to compile trough mobile device add the data base in mobile device Thanks

              D Offline
              D Offline
              Don Fizachi
              wrote on last edited by
              #6

              Try this string path = "Data Source ="; path += System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); path += "\\Database.sdf"; then myConnection = new SqlCeConnection(@path); cheers

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups