Entity Framework SQL Connection issues with Integrated Security

On one side I have a Windows service that uses Entity Framework to connect to a SQL Server instance and work with a database there.

On the other side I have a WIX based installer which has a bootstrapper .NET based GUI in which the user can enter connection details to be used in the connection string by the service. In this installer GUI I am also performing a check on the user provided data and check the database connection (using SqlConnection.Open() and even creating/dropping a database).

The issue appears in a workgroup environment, no domain controller present, and when the user chooses Integrated Security as an option. The bootstrapper application successfully connects to the SQL server and performs some operations with it, but then the Windows service fails to connect to the SQL server using Integrated Security. If I follow up by changing that to user and password authentication, the service works correctly.

Is there any way to have the bootstrapper fail connection if the service would fail, or the other way around?

Thanks.


The most likely cause is the user the service is running under and the user the installer is running under are different.

If the User running the installer has access to SQL Server through windows authentication the connection would succeed. Then if the service runs under a different account (Say LocalSystem) the user the service is running under does not have permissions to use integrated security.

The way around this to use a service account which has permissions on the server or use SQL Authentication.

I ran into this recently when deploying a service. The only way to fail the bootstrapper connection would be to run it as the account the service will run under (impersonation is one way to accomplish this) otherwise there is no way you can test the connection correctly.

Since you mention workgroups and no domain controller there may be some pass through going on with the user names and passwords. At one place I worked, on one of the SQL boxes (off the domain) each developer had a local windows account with the same password as their domain account. This allowed a pass through authentication (due to the username and passwords matching) and access to SQL Server. That may be what is going on.

链接地址: http://www.djcxy.com/p/74078.html

上一篇: 将c#连接到不同域中的SQL Server

下一篇: 集成安全性的实体框架SQL连接问题