Ado dot netconnection String with Access 2007
I am trying to connect开发者_C百科 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);
}
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.
try this connection string : Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;
Ensure that the database isn't corrupt. Repair it if necessary.
- Open the database in Access 2007.
- Go to the Tools menu, select Database Utilities and then click Compact and Repair Database.
- Locate and then click the database in the ‘Database to Compact From’ dialog box, and then click Compact.
- 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.
精彩评论