2011-03-08 39 views
0

我使用VS 2010爲Outlook 2010創建了一個加載項。我正在四處尋找存儲數據的方式,並且我看到一羣人在建議Sql CE。我嘗試過了,並不停地遇到了此問題 文件名是無效的:數據源= | DataDirectory目錄| \ data.sdfSqlServerCe文件名無效

string conString = Properties.Settings.Default.dataConn; 

     SqlCeConnection dbConn = new SqlCeConnection(conString); 

     try 
     { 
      using (SqlCeConnection con = new SqlCeConnection(conString)) 
      { 
       con.Open(); 
      } 
     } 
     catch(Exception e) 
     { 
      MessageBox.Show(e.ToString()); 
     } 

我這裏使用的顯示教程: http://www.dotnetperls.com/sqlce

任何幫助不勝感激!

謝謝。

回答

0

| DataDirectory |是運行時擴展的連接字符串中的一個特殊變量。它擴展如下:

- For applications placed in a directory on the user machine, this will be the app's (.exe) folder. 
    - For apps running under ClickOnce, this will be a special data folder created by ClickOnce 
    - For Web apps, this will be the App_Data folder 

這不適用於您的Outlook插件。我猜測它運行的上下文沒有爲它設置一個值。您可以嘗試要麼在連接字符串中提供了一個完整的數據庫路徑(更換| DataDirectory目錄|)動態地使用在應用領域或設置DataDirectory目錄的值如下:

AppDomain.CurrentDomain.SetData("DataDirectory", newpath) 

具有看看Working with local databases更多信息。