I'm facing a problem with my console application. I want to read info from Microsoft Access database and display it on console. Here's the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.OleDb;
using System.Data.Sql;

namespace _1_uzd
{
    class Program
    {
        static void Main(string[] args)
        {
            string ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;DataSource=\"studentu-db.accdb\"";
            OleDbConnection con = new OleDbConnection(ConnectionString);
            OleDbCommand cmd = new OleDbCommand("SELECT * FROM persona", con);
            con.Open();
            OleDbDataReader dataReader = cmd.ExecuteReader();
            while (dataReader.Read())
            {
                Console.WriteLine(dataReader.GetInt32(0) + "\t" + dataReader.GetString(1) + "\t" + dataReader.GetString(2));
            }
            con.Close();
            Console.ReadLine();
        }
    }
}

It should work but when I debug, the error message is shown: "OleDbExeption was unhandled. Could not find installable ISAM"...Where is the problem?

PS: I'm using Microsoft Access 2007, it that makes any sense,

有帮助吗?

解决方案

your connection string is not proper. that is main reason this error comes.

Try to correct connection string syntax as per http://www.connectionstrings.com/access/

Try with physical path like "C:\studentu-db.accdb" and if you are trying to locate access database from local folder then write "|DataDirectory|\studentu-db.accdb"

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top