简体   繁体   English

如何使用 odbc 驱动程序连接 Ms access 2010 (.accdb) 数据库

[英]How to connect Ms access 2010 (.accdb ) database with odbc driver

Can any one tell how to connect Ms access 2010 (.accdb ) database with odbc driver in c# and .NET 4.0谁能告诉如何将 Ms access 2010 (.accdb) 数据库与 c# 和 .NET 4.0 中的 odbc 驱动程序连接起来

I tried我试过

string connetionString = ("Driver={Microsoft Access Driver(*.mdb*.accdb)};DBQ=C:\\Users\\Administrator\\Desktop\\New folder\\MatchDetails.accdb;");

OdbcConnection myConnection = new OdbcConnection(connetionString);

try
{                   
    myConnection.Open();
    MessageBox.Show("Connection Open ! ");
    myConnection.Close();
}
catch (Exception ex)
{
    MessageBox.Show("Can not open connection ! ");
}

throwing this Exception抛出这个异常

ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified exception错误 [IM002] [Microsoft][ODBC 驱动程序管理器] 找不到数据源名称并且没有指定默认驱动程序异常

You have a typo in your connection string : 您的连接字符串中有错别字:

string connectionString = ("Driver={Microsoft Access Driver(*.mdb, *.accdb)};DBQ=C:\\Users\\Administrator\\Desktop\\New folder\\MatchDetails.accdb;");

(note the comma in the Driver name) (注意驱动程序名称中的逗号)

I see a two typos in driver name:我看到驱动程序名称中有两个拼写错误:

  1. There is no space before the brackets括号前没有空格
  2. There is no comma inside the brackets括号内没有逗号

Correct connection string:正确的连接字符串:

string connectionString = ("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\\Users\\Administrator\\Desktop\\New folder\\MatchDetails.accdb;");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM