2012-09-11 69 views
2

我嘗試使用ms訪問作爲數據提供者,但它給我例外。DataContext與MSAccess作爲數據提供者

static void Main(string[] args) 
    { 
     DataContext dx = new DataContext(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Data\mail.accdb;Persist Security Info=True"); 
    } 

唯一的例外是

System.ArgumentException was unhandled 
Message=Keyword not supported: 'provider'. 

這怎麼可能發生?

由於提前,

布賴恩·

回答

4

好吧,我找到了解決辦法。這有點棘手

首先創建OleDbConnection的訪問數據提供

IDbConnection connection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Data\mail.accdb;Persist Security Info=True); 

最後把它傳遞給DataContext的

DataContext dx = new DataContext(connection); 
+0

爲什麼我不能記住我的答案 – brian

+0

謝謝,這是棘手哉! –