2012-10-31 24 views
0

我有一個ASP.Net MVC 3應用程序。我爲它創建了一個安裝程序並安裝在我的網絡服務器上。Web應用程序在Web服務器上工作,但從其他機器給出錯誤

當我從網絡瀏覽器訪問應用程序"http://localhost/myapp"時,它工作。

但當我從另一臺機器,試圖像"http://mywebserver/myapp"它給了一個錯誤:

The model item passed into the dictionary is of type 'System.Web.Mvc.HandleErrorInfo', but this dictionary requires a model item of type myapp.Models.ErrorModel'.`

+0

它實際上似乎是一個潛在的錯誤正在發生,但最重要的是你您的錯誤處理代碼可能有問題。你可以嘗試禁用customErrors並刪除錯誤處理過濾器來查看底層的過濾器嗎? –

+0

我已經刪除了customerError和過濾器。一個實際的錯誤「底層提供程序在打開時失敗」。我知道它與數據庫的訪問有關,但它如何在Web服務器上工作,而不是在本地或客戶端機器上工作? –

+0

這與每臺機器上的數據庫服務器有關。我遇到了類似的問題,但我忘記了我採取的確切措施來解決問題。一種解決方法可能是在啓動它之前刪除數據庫日誌文件(如果可以的話),而不是「其他機器」。真正的解決方案與連接字符串設置和數據庫服務器本身有關。對不起,我沒有更具體。 – Ecnalyr

回答

0

按: http://blogs.msdn.com/b/dataaccesstechnologies/archive/2012/08/09/error-quot-the-underlying-provider-failed-on-open-quot-in-entity-framework-application.aspx

這可能是在新服務器上權限問題等

 
Solution 1:

In the existing connection string to remove the 「user Instance=true」 and it works.

Probable cause of the issue could be as below: The user instance cannot attach the database because the user does not have the required permissions. The user instance executes in the context of the user who opened the connection—not the normal SQL Server service account. The user who opened the user instance connection must have write permissions on the .mdf and .ldf files that are specified in the AttachDbFilename option of the connection string.

Another common issue is when you open a database file successfully when the database is attached to the SQL Server Express instance, but fails when you try to open it from the Visual Studio IDE. This might occur because the SQL Server Express instance is running as "NT AUTHORITY\NETWORK SERVICE," while the IDE is running as windows account. Therefore, the permissions may not work.

A variation of this issue is when the user that opens the user instance connection has read permissions on the database files but does not have write permissions. If you get a message saying that the database is opened as read only, you need to change the permissions on the database file.

The other main issue with user instances occurs because SQL Server opens database files with exclusive access. This is necessary because SQL Server manages the locking of the database data in its memory. Thus, if more than one SQL Server instance has the same file open, there is the potential for data corruption. If two different user instances use the same database file, one instance must close the file before the other instance can open it. There are two common ways to close database files, as follows.

User instance databases have the Auto Close option set so that if there are no connections to a database for 8-10 minutes, the database shuts down and the file is closed. This happens automatically, but it can take a while, especially if connection pooling is enabled for your connections.

Detaching the database from the instance by calling sp_detach_db will close the file. This is the method Visual Studio uses to ensure that the database file is closed when the IDE switches between user instances. For example, you are using the IDE to design a data-enabled Web page. You press F5 to run the application. The IDE detaches the database so that ASP.NET can open the database files. If you leave the database attached to the IDE and try to run the ASP page from your browser, ASP.NET cannot open the database because the file is still in use by the IDE.

相關問題