Search code examples
iisasp.net-corelocaldb

Cannot host use LocalDB in web app when hosting on IIS (Windows 10)


I am struggling to get my ASP.NET core (1.1.0) app running properly under IIS on Windows 10. Although the app is running and accessible from localhost it cannot access the associated database. The database itself is the (localdb)\ProjectV13 type that was installed along with VS2015 community. If I run the app directly from PublishOutput folder using 'dotnet .dll' then everything works as expected. Have googled/SO'd for a solution but still no further with this. The next thing I was thinking of was to install the SQL express separately along with SSMS tools to see if that would work.

Can anyone help?


Solution

  • You shouldn't use localdb when hosting in IIS. LocalDB is launched in the context of the user running it.

    That being said, the LocalDB databases owned and accessible by the user who creates it. In IIS you don't have a Profile by default. While there are workarounds, they are all more or less dirty and not an option. Read more on in this two Blog posts (Part 1 and Part 2)

    Install either SQL Server Express or the full version of SQL Server. Or use Sqlite if you need a lightweight database which doesn't require a server running in the background.

    LocalDB is only there to easy the development w/o requiring to install SQL Server Express or SQL Server full version.