我在做一個訪問Microsoft Access數據庫的示例程序。它是一個.accdb文件。數據庫的名稱是ACRONYM_DB.accdb,並有一個名爲ACRONYM的數據表。我的代碼如下:Microsoft Access錯誤找不到.mdb,但數據庫是.accdb
string currentLoc = System.AppDomain.CurrentDomain.BaseDirectory.ToString();
ObservableCollection<Acronym.Acronym> acrOC = new ObservableCollection<Acronym.Acronym>();
string ConnStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + currentLoc + "\\Assets\\ACRONYM_DB.accdb;Jet OLEDB:Database Password=password";
OleDbConnection MyConn = new OleDbConnection(ConnStr);
MyConn.Open();
OleDbCommand myCommand = MyConn.CreateCommand();
myCommand.CommandText = "SELECT * FROM ACRONYM_DB.ACRONYM WHERE ACRONYM_NAME=" + acrName;
OleDbDataReader myReader = myCommand.ExecuteReader();
在執行讀寫行我流汗錯誤:
System.Data.OleDb.OleDbException was unhandled by user code
HResult=-2147467259
Message=Could not find file 'C:\Users\Mark\Desktop\release\ACRONYM_DB.mdb'.
Source=Microsoft Office Access Database Engine
ErrorCode=-2147467259
StackTrace:
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.OleDb.OleDbCommand.ExecuteReader()
at AcronymFinder.Model.Database.AcronymDatabase.HistoricalDef(String acrName) in c:\Users\Mark\Documents\Visual Studio 2013\Projects\AcronymFinder\AcronymFinder\Model\Database\AcronymDatabase.cs:line 28
at AcronymFinder.ViewModel.MainViewModel.set_SelectedAcronym(Acronym value) in c:\Users\Mark\Documents\Visual Studio 2013\Projects\AcronymFinder\AcronymFinder\ViewModel\MainViewModel.cs:line 315
InnerException:
我知道錯誤一定是與我使用的查詢,但它是什麼我需要做不同的事情嗎?我也是使用訪問的64位版本的2013年
如果從表名中刪除'ACRONYM_DB.'會怎樣? – juharr