Absolute Thoughts....

  Home  |   Contact  |   Syndication    |   Login
  9 Posts | 0 Stories | 12 Comments | 0 Trackbacks



Post Categories

This was a common error which we get when we are using LocalDB for a website running under IIS. Everything will work fine if we run the website under IIS Express i.e. when we run through Visual Studio. Once we deploy the site into actual IIS we get an error as shown below.

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. Error occurred during LocalDB instance startup: SQL Server process failed to start. )

This error message will not give a clear idea but we will get additional information in Windows Event log. Looking in the Application section under Windows Logs we find the following message:

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.

This message clearly says, the problem we're facing is that the user profile needs to be loaded.

To fix this we need to edit applicationHost.config file which is usually located in C:\Windows\System32\inetsrv\config. Enabling loadUserProfile is not enough to fully load user profile, we also need to enable setProfileEnvironment, i.e. set to true.

    <add name="DefaultAppPool" />
    <add name="Classic .NET AppPool" managedRuntimeVersion="v2.0" managedPipelineMode="Classic" />
    <add name=".NET v2.0 Classic" managedRuntimeVersion="v2.0" managedPipelineMode="Classic" />
    <add name=".NET v2.0" managedRuntimeVersion="v2.0" />
    <add name=".NET v4.5 Classic" managedRuntimeVersion="v4.0" managedPipelineMode="Classic" />
    <add name=".NET v4.5" managedRuntimeVersion="v4.0" />
    <applicationPoolDefaults managedRuntimeVersion="v4.0">
        <processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />

Happy coding…!!! Winking smile

posted on Friday, November 6, 2015 7:12 PM