-3

I think my problem is in line 22. Visual Studio said

An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll

Additional information: The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.

in line 26.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.OleDb;
using System.Data;
using System.Windows.Forms;
using System.Web;

namespace moshaveramlak
{
    public class House
    {
        // The method for inserting into database.
        public void SaveHouse()
        {
            OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\alireza\\Documents\\House.accdb");
            try
            {
                conn.Open();
                // Insert code to process data.
            }
            /*catch (Exception ex)
            {
                MessageBox.Show("Failed to connect to data source");
            }*/
            finally
            {
                conn.Close();
            }
        }
    }
}
Evan Parsons
  • 1,139
  • 20
  • 31
  • 10
    Have you installed the Microsoft.ACE.OLEDB.12.0 driver? Please check quickly. – Nick.Mc Aug 15 '14 at 14:17
  • 1
    Thousands of links when you try a search for this. Always the same problem. Look if this is your case http://stackoverflow.com/questions/17716207/the-microsoft-ace-oledb-12-0-provider-is-not-registered-on-the-local-machine-w/17716238#17716238 – Steve Aug 15 '14 at 14:19

1 Answers1

0

Make sure you have the Microsoft Access Database Engine actually installed on the system running the application.

If you haven't installed it, it can be downloaded at http://www.microsoft.com/en-us/download/details.aspx?id=13255. The 32 or 64 bit version can be chosen after clicking the download link.

Evan Frisch
  • 1,334
  • 5
  • 22
  • 40