简体   繁体   English

Windows服务SQL Server Windows身份验证

[英]Windows Service SQL Server Windows Authentication

<add name="NuspayTransactionSecurityEntities" 
     connectionString="metadata=res://*/Security.NTPSecurity.csdl|res://*/Security.NTPSecurity.ssdl|res://*/Security.NTPSecurity.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=192.168.10.11;initial catalog=SP_PROCESSOR;persist security info=False;;MultipleActiveResultSets=True;App=EntityFramework&quot;" 
     providerName="System.Data.EntityClient" />
<add name="NPTransaction" 
     connectionString="metadata=res://*/Transaction.NPTransaction.csdl|res://*/Transaction.NPTransaction.ssdl|res://*/Transaction.NPTransaction.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=192.168.10.11;initial catalog=SP_PROCESSOR;persist security info=False;MultipleActiveResultSets=True;App=EntityFramework&quot;" 
     providerName="System.Data.EntityClient" />
<add name="CBCommon" 
     connectionString="metadata=res://*/Common.CBCommon.csdl|res://*/Common.CBCommon.ssdl|res://*/Common.CBCommon.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=192.168.10.11;initial catalog=SP_PROCESSOR;persist security info=True;persist security info=False;MultipleActiveResultSets=True;App=EntityFramework&quot;" 
     providerName="System.Data.EntityClient"/>
<add name="ApplicationServices" 
     connectionString="data source=192.168.10.11;initial catalog=SP_PROCESSOR;persist security info=True;persist security info=False;" 
     providerName="System.Data.SqlClient"/>

My problem is Windows authentication is not working if I use this application as a Windows service but it's working well in an IIS web application. 我的问题是,如果我将此应用程序用作Windows服务,则Windows身份验证将无法正常运行,但在IIS Web应用程序中它将运行良好。

I believe the service account which has configured to run windows service does not permission to connect to SQL ? 我相信已配置为运行Windows服务的服务帐户无权连接到SQL

If this is the case, you need to make sure the user under which the service is running has permissions within SQL . 如果是这样的话,你需要确保该服务是其下运行的用户有权限内的SQL

If you look in System, Administrative Tools, Services and find your service. 如果您在“系统”,“管理工具”,“服务”中查找并找到您的服务。 You can adjust the credentials associated with it. 您可以调整与其关联的凭据。

When you run is IIS , the identity under which it is run is that of the app pool identity who's has permission to connect to SQL. 当您运行的是IIS ,运行该identity就是有权连接到SQL的app pool identity

Often when we install services they install against the Network Service or Local System security principles. 通常,当我们安装服务时,它们会根据Network Service or Local System安全性原则进行安装。 These shouldn't be given access to SQL. 这些不应该被授予访问SQL的权限。

You could also create an SQL user and use a connection string which implements SQL authentication instead. 您还可以创建一个SQL user并使用实现SQL authentication连接字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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