0

I have an ASP.Net MVC 3 application. I have created a setup for it and installed on my webserver.

When I access the application from a web browser at "http://localhost/myapp", it works.

But when I tried from another machine, like "http://mywebserver/myapp" it's giving an error:

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'.`

David Cain
  • 16,484
  • 14
  • 65
  • 75
sanjay jadam
  • 221
  • 1
  • 3
  • 8
  • It actually seems like an underlying error is occurring but on top of that you might have a problem with your error handling code. Could you try disabling customErrors and removing your error handling filter to see the underlying one? – Pablo Romeo Oct 31 '12 at 06:16
  • I have removed the customerError and filter. An actual error "The underlying provider failed on Open". I know its related to access of database but how its works on web server and not works in local or client machine?? – sanjay jadam Oct 31 '12 at 09:52
  • This has something to do with the database server on each machine. I've had a similar problem, but I forget the exact course of action I took to fix it. One work-around may be to delete your database log file (if you're able to do so) before launching it no the 'other machine.' The real solution has to do with your connection string settings and the database server itself. Sorry I'm not being more specific. – Ecnalyr Oct 31 '12 at 10:56

1 Answers1

0

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

It could be a permissions issue on the new server, etc

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.

Adam Tuliper
  • 29,982
  • 4
  • 53
  • 71