Guille
Guille

Reputation: 377

Problems when deploy my webapi in the iis

I have a webapi in .Net Core 2.1. I have used Microsoft SQL Management Studio that came with Visual Studio 2017 to make a database that the webapi use to handle its data. When I run it (webapi) on VisualStudio it works fine, I can make calls through POSTMAN and I get responses pretty well, but the problem appears when I deploy the webapi on my local IIS. I get this error page :

An error occurred while starting the application. Win32Exception: Unknown error (0x89c50118) Unknown location SqlException: 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. Cannot create an automatic instance. See the Windows Application event log for error details. ) System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, object providerInfo, string newPassword, SecureString newSecurePassword, bool redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, bool applyTransientFaultHandling) Win32Exception: Unknown error (0x89c50118)

I have the same connectionString in the appsetting.json because the database is the same when I run the webapi in visual studio, so, I don't know what I'm doing wrong.

Do I need to make any specific configuration on IIS or DataBase? Any help, please?

Upvotes: 0

Views: 2915

Answers (2)

Muhammad Arshad Awan
Muhammad Arshad Awan

Reputation: 21

I had the same issue with MS LocalDB. It's true that this error is due to sql server permission. However, in my case I tried to grant permission and even added my user in "Edit site->Connect as" of IIS Site Manager but it didn't work with LocalDB.

My Fix: Since we need to host our web site with a SQL server so I uploaded the database on SQL server and changed the connection string in appsettings.json like below:

"IdentityDbContextConnection": "Server=TestServer001\sqlexpress;Database=WEBPROJECTDB;Integrated Security=SSPI;"

and Web.Config

Upvotes: 0

Khai Nguyen
Khai Nguyen

Reputation: 945

When you run webapi on Visual Studio, Visual Studio starts IISExpress with your local account and this account will connect database (look connection string: Data Source=.\SQLEXPRESS;Initial Catalog=database;Integrated Security=True). That account have permission to database as default.

And now if you want to run your webapi on IIS, there are 2 ways:

  1. Add an account that can access your database and change your connection string

  2. Add IIS Application Pool Identity Account from SQL Management Studio then change permission.

Upvotes: 2

Related Questions