Asp.net mvc 3 Web应用程序在Web服务器上工作,但从其他计算机发出错误

Asp.net mvc 3 Web应用程序在Web服务器上工作,但从其他计算机发出错误,asp.net-mvc-3,web-deployment-project,Asp.net Mvc 3,Web Deployment Project,我有一个ASP.NETMVC3应用程序。我已经为它创建了一个安装程序,并安装在我的Web服务器上 当我从的web浏览器访问应用程序时http://localhost/myapp“,它可以工作 但是当我在另一台机器上尝试时,比如“http://mywebserver/myapp“它给出了一个错误: 传入字典的模型项的类型为“System.Web.Mvc.HandleErrorInfo”,但此字典需要myapp.Models.ErrorModel”类型的模型项` 根据: 这可能是新服务器上的权限

我有一个ASP.NETMVC3应用程序。我已经为它创建了一个安装程序,并安装在我的Web服务器上

当我从
的web浏览器访问应用程序时http://localhost/myapp“
,它可以工作

但是当我在另一台机器上尝试时,比如
“http://mywebserver/myapp“
它给出了一个错误:

传入字典的模型项的类型为“System.Web.Mvc.HandleErrorInfo”,但此字典需要myapp.Models.ErrorModel”类型的模型项`

根据:

这可能是新服务器上的权限问题,等等

解决方案1:

在现有的连接字符串中删除“user Instance=true”,它就可以工作了

问题的可能原因如下: 用户实例无法附加数据库,因为该用户没有所需的权限。用户实例在打开连接的用户的上下文中执行,而不是在普通SQL Server服务帐户中执行。打开用户实例连接的用户必须对连接字符串的AttachDbFilename选项中指定的.mdf和.ldf文件具有写入权限

另一个常见问题是,当数据库连接到SQL Server Express实例时,成功打开数据库文件,但在尝试从Visual Studio IDE打开时失败。这可能是因为SQL Server Express实例以“NT AUTHORITY\NETWORK SERVICE”运行,而IDE以windows帐户运行。因此,权限可能不起作用

此问题的一个变体是,打开用户实例连接的用户对数据库文件具有读取权限,但没有写入权限。如果收到消息说数据库以只读方式打开,则需要更改对数据库文件的权限

用户实例的另一个主要问题是,SQL Server以独占访问权限打开数据库文件。这是必要的,因为SQL Server管理其内存中数据库数据的锁定。因此,如果多个SQL Server实例打开了同一个文件,则可能会导致数据损坏。如果两个不同的用户实例使用相同的数据库文件,则一个实例必须先关闭该文件,然后另一个实例才能打开该文件。有两种常用的关闭数据库文件的方法,如下所示

用户实例数据库设置了自动关闭选项,因此,如果在8-10分钟内没有与数据库的连接,数据库将关闭,文件也将关闭。这会自动发生,但可能需要一段时间,特别是在为连接启用连接池的情况下

通过调用sp_detach_db将数据库与实例分离将关闭该文件。这是VisualStudio用于确保在IDE在用户实例之间切换时关闭数据库文件的方法。例如,您正在使用IDE设计一个支持数据的网页。您可以按F5来运行应用程序。IDE分离数据库,以便ASP.NET可以打开数据库文件。如果将数据库附加到IDE并尝试从浏览器运行ASP页,ASP.NET将无法打开数据库,因为IDE仍在使用该文件。

实际上,似乎发生了潜在错误,但除此之外,您的错误处理代码可能存在问题。能否尝试禁用customErrors并删除错误处理筛选器以查看基础筛选器?我已删除customerError和筛选器。实际错误“基础提供程序在打开时失败”。我知道它与数据库访问有关,但它如何在web服务器上工作,而不是在本地或客户端机器上工作??这与每台机器上的数据库服务器有关。我也遇到过类似的问题,但我忘记了我为解决它所采取的确切行动。解决方法之一可能是在“其他机器”启动数据库日志文件之前删除它(如果您能够这样做)。真正的解决方案与您的连接字符串设置和数据库服务器本身有关。对不起,我没有说得更具体。 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.