Last post May 23, 2019 07:45 PM by crhama
May 22, 2019 07:25 PM|crhama|LINK
I'm supposed to run an angular application that talks to web api .net core application that's connected to an
Sql Server instance. on my local Windows 10 laptop. I was able to deploy both the angular and the .net core applications and run them using
IIS. Where I'm having some difficulty to connect the asp.net core to
Sql Server when the application is running on IIS. The same code is running just fine on
Visual Studio. However, when deployed on IIS, it's throwing a
500 error code.
This is the code I'm using to connect to the database.
"MembersDatabase": "Data Source=.;Initial Catalog=MembersDb;Integrated Security=True"
The database is located in the same laptop. Why it's working on Visual Studio not in
IIS? Is there anything any to do?
Thanks for helping
May 22, 2019 07:31 PM|bruce (sqlwork.com)|LINK
when running under visual studio, the app.net core app is running under your account. when running in IIS is running under the app pool account, which likely does not have access to the sqlserver.
it best practice even on you own box to create a service account that the IIS uses, and give this account permissions, rather than just make the app pool account yours.
May 22, 2019 07:59 PM|crhama|LINK
Can you post one or more links so I can see I to do what you are suggesting?
May 22, 2019 08:11 PM|Mikesdotnetting|LINK
Your connection string is for a Windows account - the account that the application process uses. On your ox, that is likely to be the admin account that also has permission to connect to SQL Server and do everything - the equivalent to the sa account in
SQL Server. On a web server, it will be the IIS App pool account. That's a limited windows account that probably can't even connect to SQL Server, let alone run any queries.
Bruce is suggesting that you create a user in SQL Server - a login that has permission to do what is necessary, typically it should be a member of db_datareader and db_datawriter roles and should map to the database that you want to connect to. Then you
pass the credentials for the user in the connection string: https://www.connectionstrings.com/sqlconnection/standard-security/
Here's some documentation on the different types of users and how to create them: https://docs.microsoft.com/en-us/sql/relational-databases/security/authentication-access/create-a-database-user?view=sql-server-2017
May 23, 2019 01:50 AM|Xing Zou|LINK
Besides, have you tried a workaround which changes IIS settings Identity to LocalSystem instead of ApplicationPoolIdentity according to the setps of Robotron in
IIS Manager Application Pools Find the pool your app belongs to Right click -> Advanced Settings Scroll down to Identity Change from whatever (for me it was ApplicationPoolIdentity, same as you have) into LocalSystem.
May 23, 2019 07:45 PM|crhama|LINK
I didn't, but for learning purposes, I'll try as well. Thank you