0

I got two problems: First, i'm trying to connect my windows form app with my embedded database (.dbf) and i keep getting this message no matter what i do to the connection string: "error isam instalable cant be found"

Second, i would like to make the path relative to the executable.

Thanks, here is the code i'm using to test the whole thing:

    private void bGuardar_Click(object sender, EventArgs e)
    {
        try
        {
        string cadena = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source =D:\\; Extended Properties = dBASE IV; UserID =; Password =;";
        OleDbConnection con = new OleDbConnection();
        con.ConnectionString = cadena;
        con.Open();
        MessageBox.Show("conected");
        con.Close();
        }
        catch (OleDbException exp)
        {
            MessageBox.Show("Error: " + exp.Message); 
        }


    }

2 Answers2

1

For the second part, you can get the path of your executable using System.IO.Path.GetDirectory(Application.ExecutablePath). There are more ways do this based upon your need (see Best way to get application folder path).

Community
  • 1
  • 1
Vijay
  • 481
  • 3
  • 5
  • 13
  • string app = Path.GetDirectoryName(Application.ExecutablePath); string cadena = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source ="+app+"; Extended Properties = dBASE IV; UserID =; Password =;"; I'm trying this now but i does not work also if i use GetDirectory instead of GetDirectoryName it gives me an error. Thanks for the answer tho – Fabrizio Bruzzese Jul 17 '16 at 01:03
0

To avoid further difficulties instead of 'OleDbConnection con = new OleDbConnection();' try

using (OleDbConnection con = new OleDbConnection())
{
    ; // your command and executes here
}

this way you call the dispose / close method always (using generally wraps up your code so that the part between { and } is wrapped in a try / catch block with finally that calls a dispose() / close() on the OleDbConn object.

PawelSz
  • 164
  • 6