Iis Connecting to Localdb

IIS connecting to LocalDB

You should use Shared Instances feature of LocalDB. 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.

(note: the original links are no longer available, using archive.org instead)

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

Original (non-working as of March 2019) links:

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

IIS Express not able to connect to LocalDB

You must add a pool
As long as the AppPool name actually exists, the login should now be created.

How I've gotten it to work is:

  1. In SQL Server Management Studio, look for the Security folder (the security folder at the same level as the Databases, Server Objects, etc. folders...not the security folder within each individual database)
  2. Right click logins and select "New Login"
  3. In the Login name field, type IIS APPPOOL\YourAppPoolName - do not click search
  4. Fill whatever other values you like (i.e., authentication type, default database, etc.)
  5. Click OK

Or

CREATE LOGIN [IIS APPPOOL\MyAppPool] FROM WINDOWS;
CREATE USER MyAppPoolUser FOR LOGIN [IIS APPPOOL\MyAppPool];

asp.net app on IIS can't connect to localdb

Turns it's not too complicated, but my inexperience with both IIS and Databases made it confusing. Hopefully this can help someone in the future. There might be some minor steps/tweaks I missed out but that's because the whole solution took a while to setup.

  1. Make sure you have SQL Server actually installed. You can download the 2008 version which I used here. Can be a pain to setup and I actually messed up when installing, here is the vid I watched (I didn't install: Database Engine Services).
  2. Next you want to make sure the IIS identity (IIS APPPOOL\ASP.NET v4.0 in my case) has permission to connect to the Database server. Check the answer here.
  3. Once it has connected to the database server, it need's to be able to connect to a database on the server (I didn't know that a database and a database server are 2 different things). You need to do something simular to Step 2, in SSMS expand the databases folder, and select the database you which to grant access too, there is a security folder in there as well and you want to add the Identity to that folder.

Other useful points:

  • If your sql configuration manager isn't opening please tell it to, thank you gofr1. This is a very useful tool for checking up on your database connection (as it turns out)
  • Make sure you setup your connectionString to point to the sql server. Make sure it doesn't connect to the mdf file with AttachDbFilename=|DataDirectory|\your_database_name_here.mdf located in the connectionString.
  • For asp.net Core read the documentation it is god, as the errors are non-existent once the app is deployed on IIS it will help in dark times. Always check publishOptions.

To further help you understand how the whole process works, thank you to gofr1
read here. Didn't solve the issue but worth a read.

Might include more stuff in here later if I remember I missed anything out.

ASP.NET deployment to IIS connects to localdb but always shows transient failure error

The error unfortunately is generic, it only says that something went wrong and possibly is a transient failure. But my issue is actually solved, for those experiencing the same issue as I am here is how to solve it.

Instead of using localdb you should download and set up SQL Express, it is like a local server but shared with all users on the PC, you will need that because when IIS tries to open your localdb it will actually do so as its own user, and so the localdb is different. Remember to change your connection string on the app, it should look something like this: "DefaultConnection": "Server=.\\SQLEXPRESS;Database=PaymentConnect;Trusted_Connection=True;"

After doing that you need to create a security user on the DB like so:

IIS APPPOOL\nameOfMyAppPool

where nameOfMyAppPool is the name of the Application pool your website is using.

Now after that what I did, which I am not sure is needed, is that I gave this security user sysadmin Server Roles, you will see this when creating this user, also on user mapping you select your DB and give it db_datareader db_datawriter and db_owner for it.

After doing that go to your DB and click to see its properties, you will need to go to permissions and give this new user you just created permissions to:

     select delete insert update connect replication execute references control

Once more I would like to remind that this is how I resolved the issue, I am not sure which of these are really necessary or not.

And that should do the trick.

ASP.NET Core Web 3.1 - IIS Express can fetch data from localdb but local IIS can not

Tried switching Application Pool Identity to my currently logged in user that I know has access via SSMS:

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. )

With this and the comment from @nilsK I fixed 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.

Sample Image

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

https://learn.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:

Sample Image



Related Topics



Leave a reply



Submit