[英]How to give SQL access to NETWORK SERVICE account?
I am trying to create a schema and a table that is accessible by a Windows Service that I wrote, but my service is unable to gain access to it... 我正在尝试创建一个可由我编写的Windows服务访问的模式和表,但我的服务无法访问它...
USE [tempdb]
GO
CREATE SCHEMA [blah]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [blah].[domains](
[id] [int] NOT NULL,
[name] [varchar](256) NOT NULL,
CONSTRAINT [PK_domains] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
A very simple table.. When I try to SELECT
it via my Windows Service, I'm getting: 一个非常简单的表..当我尝试通过我的Windows服务
SELECT
它时,我得到:
System.Data.SqlClient.SqlException (0x80131904): The SELECT permission was denied on the object 'domains', database 'tempdb', schema 'blah'. System.Data.SqlClient.SqlException(0x80131904):对象'domains',数据库'tempdb',schema'blah'上的SELECT权限被拒绝。
I've tried switching my Service account from LocalService
to NetworkService
but it gives the same thing. 我已经尝试将我的服务帐户从
LocalService
切换到NetworkService
但它提供了相同的功能。
The connection string I am using for my service: 我用于服务的连接字符串:
connectionString="Data Source=.\SQLEXPRESS;Database=tempdb;Integrated Security=True;MultipleActiveResultSets=True"
I've also tried to create a new Logins for NT AUTHORITY\\NETWORK SERVICE
, then a user NETWORK SERVICE
mapped to that Login and then grant permission on blah
as well as domains
table, but still not working. 我还试图为
NT AUTHORITY\\NETWORK SERVICE
创建一个新的登录,然后一个用户NETWORK SERVICE
映射到该登录,然后授予blah
和domains
表的权限,但仍然无法正常工作。
PS: The same code was able to access the table when I ran it as a normal executable, but not when is running as a Service
. PS:当我将其作为普通可执行文件运行时,相同的代码能够访问该表,但是当作为
Service
运行时则不能。
We discussed a few approaches in the comments, but I think your best bet is to: 我们在评论中讨论了一些方法,但我认为最好的办法是:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.