문제

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