Getting “Cannot find installable ISAM” error

2019-08-30 05:12发布

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,

标签: oledb isam
1条回答
做个烂人
2楼-- · 2019-08-30 05:42

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"

查看更多
登录 后发表回答