how to connect to access 2007 with c#

夙愿已清 提交于 2019-12-08 04:32:03

问题


hey, i am new at connecting to dataBases and for some reason each time i use those following lines my program collapse:

    string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;DataSource=|DataDirectory|\Company.accdb"
    OleDbConnection con = new OleDbConnection(connectionString);

inside my debug folder i got Company.accdb access file edit: i am getting 'Microsoft.Ace.OLEDB12.0' provider is not registered on the local machine any idea how to solve it? thanks in advance for your help


回答1:


Two things -

  1. This connection string rely on ACE OLEDB provider (typically comes with Office 2007 - your machine need to have this provider)
  2. Connection string is requesting data dictionary. You probably need to use below form:

    Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;Persist Security Info=False;

For password protected files, form would be Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;Jet OLEDB:Database Password=MyDbPassword;

I will also suggest trying different Provider (ODBC perhaps) instead. For various connection strings for Access 2007, refer http://www.connectionstrings.com/access-2007



来源:https://stackoverflow.com/questions/4427523/how-to-connect-to-access-2007-with-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!