2012-04-11 102 views
0

我在我的網站上建立了一個註冊頁面在VS2010中,當我填寫表單在點擊註冊時,我收到以下錯誤。幫助將不勝感激。插入錯誤:目錄查找文件

System.Exception was unhandled by user code 
     Message=Insert Error:Directory lookup for the file "C:\Users\myname\Documents\myname\Project\App_Data\SJDatabase.mdf" failed with the operating system error 5(error not found). 
    Cannot attach the file 'C:\Users\myname\Documents\myname\Project\App_Data\SJDatabase.mdf' as database 'SJDatabase'. 

連接字符串:

<connectionStrings> 
     <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/> 

    <add name="MyConsString" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|SJDatabase.mdf; 
          Initial Catalog=SJDatabase; 
          Integrated Security=SSPI;" 
          providerName="System.Data.SqlClient" /> 
    </connectionStrings> 
+0

你確定路徑'C:\ Users \ myname \ Documents \ myname \\ Project \ App_Data'存在嗎? – GolfWolf 2012-04-11 14:14:09

+0

你可以發佈你的一些代碼嗎?連接字符串主要是 – Diego 2012-04-11 14:14:41

+0

@ w0lf是的,它確實存在,輸入錯誤,請查看更新的版本。 – user1300580 2012-04-11 14:22:54

回答

1

我認爲你缺少|DataDirectory|\SJDatabase.mdf

也是一個反斜槓,你有集成安全性= SSPI兩次,我不認爲你需要的AttachDBFileName部分

試試這樣更簡單的東西:

"data source=ServerName;Initial Catalog=SJDatabase;Integrated Security=SSPI" providerName="System.Data.SqlClient" 
+0

現在可以工作,但是我得到一個新的錯誤:SqlParameterCollection只接受非空的SqlParameter類型對象。 參數名稱:值 – user1300580 2012-04-11 15:18:42

+0

你什麼時候得到的? – Diego 2012-04-11 15:29:12