简体   繁体   English

数据库权限与Windows服务的工作方式不同吗?

[英]Database permissions work differently from a windows service?

I have a console application that also runs as a windows service (see: .NET console application as Windows service ) 我有一个控制台应用程序,它也可以作为Windows服务运行(请参阅: .NET控制台应用程序作为Windows服务

It runs a stored proc that works on my local db, however over the network it only works as a console app, the service gives "SqlException (0x80131904):Cannot find the object or you don't have permission". 它运行可在我的本地数据库上运行的存储proc,但是在网络上它只能作为控制台应用程序使用,该服务给出“ SqlException(0x80131904):找不到对象或您没有权限”。

The user account has db owner permissions. 该用户帐户具有数据库所有者权限。

The very first thing the SP does is disable a trigger on a table, that it now says either does not exist or I don't have permission to access. SP要做的第一件事是禁用表上的触发器,现在它说要么不存在,要么我没有访问权限。

I am new to windows services, is there something I am missing? 我是Windows服务的新手,是否缺少某些东西? Do they work differently in this regard? 他们在这方面的工作是否有所不同?

Its a sqlserver 2012 instance on another devs machine over the local network. 它是本地网络上另一台开发机上的sqlserver 2012实例。

Connection string: 连接字符串:

 <add name="XYZ_ConnectionString" connectionString="Data Source=PCNAME\sql2012;Initial Catalog=DB_Name;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>

EDIT: I have noticed that an earlier part of the service that does a select on a table from the DB is working correctly, which suggests the connection is working? 编辑:我注意到服务的较早部分从数据库表上进行选择的工作正常,这表明连接正在工作?

Thanks 谢谢

You're using Windows Authentication (the part of your connection string that reads Integrated Security=SSPI; ) so when you run it as a console app it is using your logged in Windows ID to authenticate. 您正在使用Windows身份验证(连接字符串的一部分,该消息读取Integrated Security=SSPI; ),因此,当您将其作为控制台应用程序运行时,它将使用登录的Windows ID进行身份验证。

SQL Servers can be configured to use Windows Authentication or "Mixed Mode", which supports a textual username and password ( details ). 可以将SQL Server配置为使用Windows身份验证或“混合模式”,该模式支持文本用户名和密码( 详细信息 )。 Note that the default is to only use Windows Authentication. 请注意,默认设置是仅使用Windows身份验证。

If you are able to add Mixed Mode auth to the SQL Server (or it's already enabled) then get the database admin to create a new user and replace the Integrated Security=SSPI; 如果您能够将混合模式身份验证添加到SQL Server(或已经启用),则请数据库管理员创建一个新用户并替换Integrated Security=SSPI; part of your connection string with something like this: 连接字符串的一部分,如下所示:

;User ID=*****;Password=*****;

If you are not able to use Mixed Mode auth at the SQL Server (some DBAs are reticent to do this) then you need to configure your Windows Service to start with a Windows Domain account - note that it must be a Domain account, rather than a local Windows account on your PC, because the SQL Server needs to get to a domain controller to authenticate the credentials. 如果您不能在SQL Server上使用混合模式身份验证(某些DBA会拒绝这样做),则需要将Windows服务配置为以Windows域帐户开头-请注意,它必须是域帐户,而不是您的PC上的本地Windows帐户,因为SQL Server需要访问域控制器以对凭据进行身份验证。

Info on configuring the service's credentials can be found here , but it's little more complex than opening the service in the service manager window, going to the "Logon" tab, and selecting the account that the service should run as. 可以在此处找到有关配置服务凭据的信息,但与在“服务管理器”窗口中打开服务,转到“登录”选项卡,然后选择服务应以其运行的帐户相比,它要复杂得多。

If the select query is running correctly that seems to be a permission issue on SQL Server on the user excuting the operations. 如果选择查询运行正常,这似乎是执行操作的用户在SQL Server上的权限问题。

Given that you are removing a trigger that does requires a different set of permissions that the ones needed to execute a select statement. 假设您要删除的触发器确实需要执行select语句所需的一组不同的权限。 I would suggest that you make sure the running user is getting proper access to the services, I would use SQL Server Profiler to log all the query and events to the database right after I run the application. 我建议您确保正在运行的用户能够正确访问服务,我将在运行应用程序后立即使用SQL Server Profiler将所有查询和事件记录到数据库中。 In there I would see the queries that are failing and have a better picture of the root of the error. 在这里,我将看到失败的查询,并且可以更好地了解错误的根源。

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

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