locked
The path is not valid. Check the directory for the database. [ Path =C:\Users\Admin\Documents\Visual Studio 2008\Projects\GMAOMobile \GMAOMobile.sdf.] RRS feed

  • Question

  • Hello every body,

    Good Morning everybody,
    I develop a csharp smart device application.I am in the step of the connection to my local database .sdf.As I read,I should add this .sdf file to my emulator using a shared folder.I did as below:
    1-sharing my file C:\Users\Admin\Documents\Visual Studio 2008\Projects\GMAOMobile
    2-in the visual studio,go to Tools->connect to device
    3-in the device tool,Menu File->configure...
    4-I add the shared file in the shared folders icon.
    Running another time,the problem still the same:cannot found the path of the database.
    I read more.I found that I can refer to my database using the storage card.But I can't Copy the DB (the sdf file) from the pc to the storage card, and, and refer to it as \\Storage card\GMAOMobile.sdf.


    can some one help me wid dis, i'm trying connecting my .sdf to my windows mobile project. but i have problems wid regards to this error


    The path is not valid. Check the directory for the database. [ Path =C:\Users\Admin\Documents\Visual Studio 2008\Projects\GMAOMobile\GMAOMobile.sdf.    ]

    can some one help me to fix this error. im working with vs2008.
    thanks in advance.

    Any help will be very grantful
    Regards

    Friday, April 16, 2010 9:23 PM

Answers

  • Hi ,

    use this function to retrieve the path of DataBase exists with your executable file :

    Private Function GetExePath() As String 
    Return (Path.GetDirectoryName(Assembly.GetExecutingAssembly.GetName.CodeBase)) 
    End Function

    In Properties Panel set your DataBase File property :

    Build Action : Content

    Copy to output : Copy if newer

    This way your DataBase will be transformed into your project directory on Emulator.

     Don't forget to add a Slash "\" before your DataBase name.

    Let me know if you need any help

     

    Regards : MrAlshahawy

     


    Please remember to mark the replies as answers if they help ,Don't forget to Vote the answer as Helpful if it helps
    • Proposed as answer by Ashraf Alshahawy Monday, April 19, 2010 12:39 AM
    • Marked as answer by warrentang Friday, April 23, 2010 2:51 AM
    Friday, April 16, 2010 9:54 PM
  • Hi,

    Thank u a lot.U propositions help me a lot to solve my issue.

    I wanna note that the path of my database is: string cc=   @ " \Storage Card\ModeDifféré\BaseGMAOLocal.sdf"

    Regards

    Friday, April 23, 2010 1:19 PM

All replies

  • Hi ,

    use this function to retrieve the path of DataBase exists with your executable file :

    Private Function GetExePath() As String 
    Return (Path.GetDirectoryName(Assembly.GetExecutingAssembly.GetName.CodeBase)) 
    End Function

    In Properties Panel set your DataBase File property :

    Build Action : Content

    Copy to output : Copy if newer

    This way your DataBase will be transformed into your project directory on Emulator.

     Don't forget to add a Slash "\" before your DataBase name.

    Let me know if you need any help

     

    Regards : MrAlshahawy

     


    Please remember to mark the replies as answers if they help ,Don't forget to Vote the answer as Helpful if it helps
    • Proposed as answer by Ashraf Alshahawy Monday, April 19, 2010 12:39 AM
    • Marked as answer by warrentang Friday, April 23, 2010 2:51 AM
    Friday, April 16, 2010 9:54 PM
  • Hi,

    I work with Csharp.Where should I put this function?

    this is my code:

    using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Runtime.InteropServices;
    using System.Runtime.Serialization;
    using System.Runtime.CompilerServices;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlServerCe;
    
    namespace ModeDifféré
    {
     public partial class Connexion : Form
     {
      public Connexion()
      {
       InitializeComponent();
      }
    
      private void Connexion_load(object sender, EventArgs e)
      {
       createconnexion();
      }
    
      private void createconnexion()
      {
       /*string chbd= Environment. + "\\BaseGmaoLocale.sdf";
       //string chcon= "Data source=\'[0]'\ BaseGmaoLocale.sdf;";
       SqlCeConnection sqlceconn= new SqlCeConnection(chcon);
       sqlceconn.Open();*/
      }
    
      private void button1_Click(object sender, EventArgs e)
      {
       /*string req = "select Login, MotPasse from Connexion";
       DataTable tab = new DataTable();
        SqlCeCommand com = new SqlCeCommand(req, sqlceconn);
       SqlCeDataAdapter ada = new SqlCeDataAdapter(com);
       ada.Fill(tab);*/
       string s1 = textBox1.Text;
       string s2 = textBox2.Text;
       SqlCeConnection cnx = new SqlCeConnection();
       string wCS = @"Data source=.\BaseGmaoLocale.sdf;";
       cnx.ConnectionString = wCS;
       cnx.Open();
       BaseGmaoLocaleDataSet2 dat = new BaseGmaoLocaleDataSet2();
       DataRow[] foundRows;
       foundRows = dat.Tables["Connexion"].Select("Login = '" + s1 + "' and MotPasse = '" + s2 + "'");
    
       if (foundRows != null)
       {
        MessageBox.Show("Authentification réussie");
        MenuP m = new MenuP();
        m.Show();
       }
       else
       {
        MessageBox.Show("Login ou mot de passe incorrect veuillez réessayer");
       }
       
       cnx.Close();
      }
     }
    }

     

    Thank u in advance if u correct me the code.I deploy the code but still the same error

    Regards

    Friday, April 16, 2010 10:32 PM
  • Hi ,

    I used a VB to C# converter , So you need to check it out.

    using System.IO;
    using 
    System.Reflection;

    private string GetExePath()

        {

            return (Path.GetDirectoryName(Assembly.GetExecutingAssembly.GetName.CodeBase));

        }

     

    {

    // Use this string variable to call the above function to return the path of your data base

        string DataBasePath = (GetExePath() + \\BaseGmaoLocale.sdf);

    }

     

    I hope that helps

    Regards :MrAlshahawy

     


    Please remember to mark the replies as answers if they help ,Don't forget to Vote the answer as Helpful if it helps
    Friday, April 16, 2010 10:49 PM
  • hi,

    I really don't understand by this step of code:

    // Use this string variable to call the above function to return the path of your data base

        string DataBasePath = (GetExePath() + \\BaseGmaoLocale.sdf );

    where should I place it correctly?

    Regards

    Friday, April 16, 2010 11:20 PM
  • Hi ,

    First : Add yourDataBase to your Solution , and set its properties in Properties Panel as follow :

    Build Action :Content

    Copy to Output directory :Copy if newer

    Now , when your project got Deployed your DataBase file would be copied into your executable file directory.

    Second :Use this function to return the path of your DataBase whenever you want to add/remove/read data from it in your code.

     

    I hope that helps.

    Regards : MrAlshahawy


    Please remember to mark the replies as answers if they help ,Don't forget to Vote the answer as Helpful if it helps
    Sunday, April 18, 2010 7:43 AM
  • hi Tunisein

    use "\\" backslash instead of single in data source field.


    if the post helpful please mark it right else feel free to correct me
    Sunday, April 18, 2010 8:08 AM
  • Hi,

    Thank u a lot.U propositions help me a lot to solve my issue.

    I wanna note that the path of my database is: string cc=   @ " \Storage Card\ModeDifféré\BaseGMAOLocal.sdf"

    Regards

    Friday, April 23, 2010 1:19 PM
  • hello ashraf fawzy ,

    I am having same problem but still i am not getting connected with the database..help me out..I have added the function u said and made setting told by u but still not getting connected to Databse.

    Thursday, October 20, 2011 7:31 AM
  • Me funcionó corrigiendo la función:

           

    private string GetExePath()

            {

                   return (Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase));

            }

    También la línea:

    string DataBasePath = (GetExePath() + "\\BaseGmaoLocale.sdf");

    Solo se agregó los paréntesis dos métodos y las comillas al nombre de la base de datos.

    Estoy desarrollando una aplicación Windows Mobile 5.0 usando SQL Server CE

    Wednesday, November 6, 2013 5:17 PM