简体   繁体   中英

IIS not passing credentials to webservice for database connections

I've spent the whole day trying to work this out. I have a new webservice that works fine when included as a project reference inside the same solution. But now I need to publish it to my local IIS so somebody else can test against it. I have applied the correct application pool to the site. The application pool is set to use Intergrated pipeline and has the correct active directory identity.

The connection string in the config file has "integrated security=True".

When the webservice sets up the connection string, it has no credentials and I get the following exception when the connection is opened: "Login failed for user ''. Reason: An attempt to login using SQL authentication failed. Server is configured for Windows authentication only. [CLIENT: ]"

When I check my database Server Properties -> Security -> Server Authentication, it has "SQL Server and Windows Authentication mode" checked.

I also confirmed that the AD account has access to the database as well.

I have looked at all kinds of other posts but can't find one that offers a solution that works for me. I must be missing something simple and just can't see it.

What am I missing?

Here is my config file:

 <configuration> <system.web> <compilation debug="true" targetFramework="4.6.1" /> <httpRuntime targetFramework="4.5.2" /> <httpModules /> </system.web> <system.webServer> <validation validateIntegratedModeConfiguration="false" /> <modules /> </system.webServer> <connectionStrings> <add name="CoreServices" connectionString="data source=localhost;initial catalog=CoreServices;integrated security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" /> </connectionStrings> </configuration> 

Try adding this line to your web.config:

<authentication mode="Windows"/>

Add it in your <System.Web> tag.

That connection string will not cause that error. Try hard-coding the connection string in your application code to troubleshoot.

It turns out the connection string wasn't being retrieved from the config file. I am having to reuse another project that provides database access. It was expecting the connection string to be in the app settings section.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM