2

I have created an MVC 4 application using the standard Internet Application template. I have added some other controllers, views, model and a connection to my own sql database which is working correctly.

When i publish this to a file location to access via my IIS8 on my windows 2012 server the application works except for when i click on logon or register links.

I have not made any changes to the registration or logon parts of the application and as such the Account controller and model have remained the same as has the DefaultConnection string in the webconfig file see below

enter <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-mvcdev-20131010105728;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-mvcdev-20131010105728.mdf" providerName="System.Data.SqlClient" />

I have a couple of registered members and have some views and controllers that require an authorised user to run correctly.

The error i get when i try to access the Account/Logon or Account/Register is:-

Server Error in '/' Application.

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details. )

The 2 event logs are

Unexpected error occurred while trying to access the LocalDB instance registry configuration. See the Windows Application event log for error details.

and

Cannot get a local application data path. Most probably a user profile is not loaded. If LocalDB is executed under IIS, make sure that profile loading is enabled for the current user.

Has anyone else come across this or have any links to some helpful resolutions?

The application was published to a folder in the Public Documents of my windows server and is being accessed currently of machines on the same LAN

JMB
  • 47
  • 1
  • 3
  • 6

2 Answers2

6

I was also suffering from same problem but there is so small solution for it just go in iis server than to application pool from which you application is running and in advance setting of application pool we will get the option of Process Model under which there is identity which is by default application pool identity just change it to Local System and your done

And Remember to Put App_Data Folder their in WWW folder of IIS server

Neeraj Mehta
  • 1,675
  • 2
  • 22
  • 45
  • I have to thank you for this answer. It's the only one that worked for me. Can you please post this answer to http://stackoverflow.com/questions/22737373/how-to-deploy-asp-net-mvc-4-application-using-localdb-to-local-iis-on-windows-7 so I can accept it? Perhaps you can elaborate on why Local System works but not Application Pool Identity. – allenylzhou Mar 29 '14 at 21:52
1

If you used the Internet Template for MVC 4 it uses SimpleMembership as the membership provider and automatically wires it up. If you did not make any changes to the basic configuration SimpleMembership is configured in the web.config to use a local database (localDB). SimpleMembership uses EF code-first with lazy initialization. So it checks if the database is available the first time you try to access any of its methods, such logon and registration. If the database is not available it tries to create it. These error messages probably indicate that it could not create this database. If I had to guess you do not have the proper privileges on the server you are deploying to to create a localDB. It is trying to create it in the App_Data folder. Check to make sure that the application has privileges to create files in this folder. The better solution for a production application is to use SQL Server and just change your connections string to point to it instead.

Kevin Junghans
  • 17,475
  • 4
  • 45
  • 62
  • Would i be correct in thinking that if i change the connection string for the default connection to a SQL Server the tables will be auto created. Or will i have to create the structure prior to amending the connection? – JMB Oct 14 '13 at 12:38
  • The connection string used by SimpleMembership is specified as the first parameter in the WebSecurity.InitializeDatabaseConnection method. If you have not changed the code generated by the Internet template it is called in the InitializeSimpleMembershipAttribute located in the Filters folder. Find the name of the connection string and modify that connection string to point wherever your SQL Server is located. If the database is not present when the InitializeDatabaseConnection method is called then EF will automatically create it for you. – Kevin Junghans Oct 14 '13 at 12:53
  • Ive changed the connection string. When i publish now i get the error **Unable to find the requested Unable to find the requested .Net Framework Data Provider. It may not be installed.] WebMatrix.Data.DbProviderFactoryWrapper.CreateConnection(String connectionString) +32476 ** – JMB Oct 15 '13 at 14:45
  • Ive checked my IIS8 application pool and its using the default pool and .net 4.5 is installed. My connection string is now `` – JMB Oct 15 '13 at 14:49
  • You are using a connection string for model-first or database-first and you probably do not have the configuration settings to use an Entity Client. Your config string should be something like this: – Kevin Junghans Oct 15 '13 at 15:01