That's because LocalDb is not intended for production use.
Specifically, this text from the article: "Typically SQL Server Express is not used for production web applications. LocalDB in particular is not recommended for production use with a web application because it is not designed to work with IIS."
So change your connectionString value to use a real sql server database and you should be good to go!
I had the same issue and here (Is it normal to use LocalDb in production?) the solution founded. @Krzysztof Kozielczyk@ provides 2 articles: first and second. Tricks from the first was enough to resolve problem in my case. Actually I just added to C:\Windows\System32\inetsrv\config\applicationHost.config
<add name="ASP.NET v4.0" autoStart="true" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated"> <processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" /> </add>
Btw, my connection string looks like your second one (with "|DataDirectory|\Database.mdf").