“未找到数据源名称并没有指定默认驱动程序”,用于创建访问连接
问题描述:
这是我在.NET连接到Access数据库:“未找到数据源名称并没有指定默认驱动程序”,用于创建访问连接
OdbcConnection conn = new OdbcConnection("Driver={Microsoft Access Driver (*.mdb)};Dbq=" + path + "\\Access.mdb;Uid=;Pwd=;");
而且我得到了这个问题:
base {System.Data.Common.DbException} = {"ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"}
我试过几个数据库连接字符串:http://www.connectionstrings.com/access,但没有一个能够工作。
对此有何建议?
在此先感谢。
答
试试这个
http://www.connectionstrings.com/
更具体地说这个
http://www.connectionstrings.com/access
我想你的代码更改为以下:
OdbcConnectionStringBuilder sb = new OdbcConnectionStringBuilder();
sb.Driver = "Microsoft Access Driver (*.mdb)";
sb.Add("Dbq", "C:\\info.mdb");
sb.Add("Uid", "Admin");
sb.Add("Pwd", "pass!word1");
OdbcConnection con = new OdbcConnection(sb.ConnectionString);
答
web.config中添加
add name="odbcConnectionString"
connectionString="Driver={Microsoft Access Driver (*.mdb)};DBQ=|DataDirectory|info.mdb; "
providerName="System.Data.OleDb"
您使用的Windows 7? – BlackICE