How to allow IIS to use local database from ASP.NET MVC project?

后端 未结 4 1018
南笙
南笙 2020-12-05 16:31

I\'m going to be demoing a ASP.NET MVC website on a local network. This application has a connection to a database:


    

        
相关标签:
4条回答
  • 2020-12-05 16:37

    See this post: These two posts on Using LocalDB with Full IIS should give you more information. Especially the second part seems relevant, but the first one contains some context as well.

    1. Part 1: User Profile
    2. Part 2: Instance Ownership

    Credit: IIS connecting to LocalDB

    0 讨论(0)
  • 2020-12-05 16:38

    The best solution is to use SQL Expression but if you don't want there are few steps that you have to do to make your mvc application work with localdb

    1. Open Visual studio command prompt as administrator
    2. execute sqllocaldb share v11.0 IIS_DB (then the database will be shared and IIS can access it)
    3. Change the site connection string to point to the shared instance of DB: Data Source=(LocalDb)\.\IIS_DB then publish again

    Note that in this point you may receive an access deny error and there is how to fix it

    1. Go to visual studio => databaseexplorer => add connection
    2. For the server name enter (LocalDb)\.\IIS_DB then right click on the connection and choose new query and execute this command

      create login [IIS APPPool\DefaultAPPPool] from windows;
      exec sp_addsrvrolemember N'IIS APPPool\DefaultAPPPool, sysadmin
      
    0 讨论(0)
  • 2020-12-05 16:50

    I solved it like this:

    Start by using Developer PowerShell or Developer Command Prompt for Visual Studio as Administrator and confirm that you only have one instance of LocalDb.

    Type sqllocaldb info to see your LocalDb instances.

    I then followed this article and had Application Pool Identity set to my currently logged in user, credit: https://stackoverflow.com/a/38294458/3850405

    https://docs.microsoft.com/en-us/archive/blogs/sqlexpress/using-localdb-with-full-iis-part-1-user-profile

    In there I found that it is not enough to have Load User Profile set to true for your Application Pool, you also need to set setProfileEnvironment to true in applicationHost.config normally located at C:\Windows\System32\inetsrv\config. With this configuration it worked:

    Original answer:

    https://stackoverflow.com/a/62810876/3850405

    0 讨论(0)
  • 2020-12-05 16:53

    When there are multiple version of SQL Server localDB installed in a machine, this error is very common.

    Try to use (localdb)\mssqllocaldb, as a common server name to connect to the LocalDB automatic instance, instead of "v11.0" or "v12.0".

    The above automatic localdb instance, have a default name across all the version and avoid conflict between name & version.

    Important: When updating the localdb to new version, remember the database created with an older version does not work with the newer.

    0 讨论(0)
提交回复
热议问题