Ado dot netconnection String with Access 2007

旧时模样 提交于 2019-12-11 17:54:51

问题


I am trying to connect with Access 2007 "accdb" file using ADO net using the following code, but i am getting the error Unrecognized Database format, What can be the possible reason for this?

        OleDbConnection conn = new 
        OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;
        Data Source=C:/MyWorkers.accdb");

        try
        {
            conn.Open();
            MessageBox.Show("Connected");


        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

回答1:


You can use the Microsoft.ACE.OLEDB.12.0 provider, see http://www.connectionstrings.com/access-2007 available as part of the office 2007 system driver package.




回答2:


try this connection string : Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;




回答3:


Ensure that the database isn't corrupt. Repair it if necessary.

  1. Open the database in Access 2007.
  2. Go to the Tools menu, select Database Utilities and then click Compact and Repair Database.
  3. Locate and then click the database in the ‘Database to Compact From’ dialog box, and then click Compact.
  4. Select an appropriate folder location for the new file in the ‘Compact Database Into’ dialog box, type a unique name for the file and then click on Save.

Use your code to open the compacted database.



来源:https://stackoverflow.com/questions/4346261/ado-dot-netconnection-string-with-access-2007

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