Question

I have seen bits and pieces related to this on the web but I still cannot figure it out. I am hosting a WCF service in IIS and on the same server I have SQL Server 2012 installed. I would like to have the WCF service to CRU&D operations on the SQL Server database.

I have read that because I am creating the connection string in a WCF service I need to treat it as a remote SQL Server instance (despite being on the same server). However, I am using integrated security with a domain user. The best answers I have seen to this are:

  1. Create a local user and use a remote connection string with that local user account: Windows Service unable to connect to SQL Server on localhost

  2. Use a remote SQL Server instance (I guess create a whole other SQL Server).

Outside of those though, I am lost. I'm wondering if there is maybe another option. Possibly one that keeps my domain user account and creates a proper connection string? Any suggestions would be greatly appreciated.

Thank you all by the way!

Was it helpful?

Solution 2

There is no connection-driven need to use a remote SQL Server instance or ditch Windows authentication in your connection string. An IIS-hosted WCF service can work fine with both.

Your connection string should look something like this:

<add name="DbConnection" connectionString="Data Source=.;Initial Catalog=MyDatabase;Persist Security Info=False;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>

Also, you may find the ConnectionStrings.com SQL Server 2012 page helpful. Over the years I have found ConnectionStrings.com invaluable for reality checking connection-string variations for different versions of SQL Server, different clients etcetera.

OTHER TIPS

Well, you have not said what the issue is with the existing connection strings. So let me explore all possibilities in this answer --

  1. Since you are using domain users to connect to your database, you would need to add either a domain/local Windows User Group to your SQL Server under Logins to permit that set of users to connect to your server. By default, everyone is denied access unless added explicitly.

  2. Next, your connection string is of the format that [J0e3gan] has already posted. In the web.config file of your WCF service, ensure you have something like this --

    <connectionStrings><add name="DbConnection" connectionString="Data Source=(local);Initial Catalog=MyDataase;Persist Security Info=False;Integrated Security=SSPI;" providerName="System.Data.SqlClient" /></connectionStrings>
    
  3. In IIS, set the "Identity" being used for your App Pool for the WCF Service to be the same as the domain user you want to use to authenticate/authorize the WCF - Database connection.

Let me know if you need further info.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top