Unrecognized database format

I would like to load some data from an access database into my C # application. But when it tries to establish a database connection, I get this error:

Unrecognized database format

How to solve this?

This is my code:

private void btnBrowseDB_Click(object sender, EventArgs e)
{
    OpenFileDialog ofd = new OpenFileDialog();
    ofd.Title = "Kies een databank.";
    ofd.Filter = "Microsoft Access Databank (*.accdb)|*.accdb";
    ofd.RestoreDirectory = true;

    if (ofd.ShowDialog() == DialogResult.OK)
    {
        txtDBLocation.Text = ofd.FileName;
        loadCampagnes(ofd.FileName);
    }
}

private void loadCampagnes(string pathDB)
{
    string connString = "Provider=Microsoft.Jet.OLEDB.4.0;"
                        + "User ID=;"
                        + "Password=;"
                        + "Data Source =" + pathDB + ";";
    try
    {
        OleDbConnection oleDbConn = new OleDbConnection(connString);

        string strSQL = "SELECT id, naam "
                        + "FROM Marketingcampagne ";

        OleDbCommand oleDbCmd = new OleDbCommand(strSQL, oleDbConn);
        oleDbConn.Open();
        OleDbDataReader oleDbReader = oleDbCmd.ExecuteReader();

        while (oleDbReader.Read())
        {
            string strCampagneNaam = "";
            int intValue;

            int intField = oleDbReader.GetOrdinal("naam");
            if (!oleDbReader.IsDBNull(intField))
                strCampagneNaam = oleDbReader.GetString(intField);

            intField = oleDbReader.GetOrdinal("id");
            if (!oleDbReader.IsDBNull(intField))
                intValue = oleDbReader.GetInt32(intField);

            lbCampagnes.Items.Add(strCampagneNaam);
        }

        oleDbConn.Close();
    }

    catch (OleDbException ex)
    {
        MessageBox.Show("Problemen bij het ophalen van de data (" + ex.Message + ")");
    }

    catch (Exception ex)
    {
        MessageBox.Show("Onbekende fout (" + ex.Message + ")");
    }
}

      

Vincent

ps. I am using Windows 7 64-bit, but I changed the target processor to x86.

+2


a source to share


2 answers


For accdb you need:

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;Persist Security Info=False;

      



- http://www.connectionstrings.com/access-2007

+5


a source


Server svr = new Server();

res.Database = "SMO";
res.Action = RestoreActionType.Database;
res.Devices.AddDevice(@"C:\SMOTest.bak", DeviceType.File);
res.PercentCompleteNotification = 10;
res.ReplaceDatabase = true;
res.PercentComplete += new PercentCompleteEventHandler(ProgressEventHandler);
res.SqlRestore(srv);

      



-3


a source







All Articles