I have a simple WCF project that uses the Entity Framework to access the AdventureWorks database. Its actually out of a book Windows Communication Foundation 4: Step by Step.
The catch is that the SQL Server database is not a local SQL Server Express instance but a full SQL Server 2008 R2 instance on an external machine called win01s305. I created a Data Model from the external Database by Generate from Database. The data access works fully with the built-in ASP.NET Web Server (Cassini?) until I publish the WCF service to IIS. Then the credentials/account are different on the remote SQL server machine and the data access stops working.
The book specifies a script if you have trouble:
USE [AdventureWorks]
GO
CREATE USER [IIS APPPOOL\DefaultAppPool] FOR LOGIN [IIS APPPOOL\DefaultAppPool]
GO
EXEC sp_addrolemember N'db_owner', [IIS APPPOOL\DefaultAppPool]
GO
GO
CREATE USER [IIS APPPOOL\ASP.NET v4.0] FOR LOGIN [IIS APPPOOL\ASP.NET v4.0]
GO
EXEC sp_addrolemember N'db_owner', [IIS APPPOOL\ASP.NET v4.0]
GO
The issue is these accounts do NOT exist on the remote SQL Server machine. The machine does not have IIS or the .NET Framework on it, just SQL Server. How can I do this?
You either have to run your app pool under a domain account and give that user rights in your database or, with mixed mode authentication turned on on the sql server, create an SQL authenticated user and put it’s name and password in your connection string.