2011-10-26 50 views
1

我正在使用Entity Framework 4.1並嘗試連接到MVC Web應用程序內的新SQLServerCE 4.0數據庫。 我使用此代碼SQLServerCE DefaultConnectionFactory

Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0", "|DataDirectory|", "test.sdf"); 

而且它會引發此異常:

Format of the initialization string does not conform to specification starting at index 86.

有什麼不對的代碼?

如果我使用

Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0") 

它的工作原理,並用很長的名字匹配我的程序集名稱創建一個數據庫。

回答

5

有點晚,但這應該幫助:

new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0", 
    "", @"Data Source=|DataDirectory|\test.sdf"); 
+0

謝謝。 它從來沒有遲到... 我試過你的建議,我得到了同樣的錯誤: 初始化字符串的格式不符合從索引71開始的規範 – user385411

+0

對不起,複製並粘貼錯誤。這適用於我! – Hubi

+0

非常感謝。 我應該認識到我對此幾乎失去了希望...... – user385411

相關問題