简体   繁体   English

将用户添加到SQL Server 2008 - 权限被拒绝

[英]Add user to SQL Server 2008 - permission denied

I have recently had some problems that I think might be helped by debugging my ASP.NET MVC application in IIS instead of with the default ASP.NET Development Server. 我最近遇到了一些问题 ,我认为可能是通过在IIS调试我的ASP.NET MVC应用程序而不是默认的ASP.NET开发服务器来帮助的。 However, when I try this the application can't access the database server (MS SQL Server 2008 Express) - it works fine on the Development Server though. 但是,当我尝试这个时,应用程序无法访问数据库服务器(MS SQL Server 2008 Express) - 它在开发服务器上工作正常。

The error I get is 我得到的错误是

Cannot open database 'myDbName' requested by the login. The login failed. Login failed for user 'NT INSTANCE/NETWORK SERVICE'.

I assume it worked before because the development server accessed the database through my user account, and not via the network service like IIS . 我认为它之前有效,因为开发服务器通过我的用户帐户访问数据库,而不是通过IIS等网络服务。

I tried adding the user NETWORK SERVICE to the database, but it turns out I don't have the user privileges to do so - it doesn't matter that my Windows account that I log on to the server with is admin, or that I run the program in an administrator context. 我尝试将用户NETWORK SERVICE添加到数据库,但事实证明我没有这样做的用户权限 - 我登录到服务器的Windows帐户是admin,或者我没关系在管理员上下文中运行该程序。 I just can't add another user to the DB. 我只是无法将另一个用户添加到数据库中。

How do I solve this problem? 我该如何解决这个问题?

You could change the user that IIS runs under: it's a setting in the properties for the ApplicationPool that your web site's running under. 您可以更改IIS运行的用户:它是您的网站运行的ApplicationPool属性中的设置。

We do this all the time as it gives us better control over user access - that NT INSTANCE/NETWORK SERVICE account's a bit too magic for my liking... 我们一直这样做,因为它让我们更好地控制用户访问 - NT INSTANCE / NETWORK SERVICE帐户对我来说有点太神奇......

NETWORK SERVICE is a special account. NETWORK SERVICE是一个特殊帐户。 If your database server is on another machine from your IIS server, you need to add the account: 如果数据库服务器位于IIS服务器的另一台计算机上,则需要添加该帐户:

\\$ as a user for the database. \\ $作为数据库的用户。 So if you're on a IIS Server called LISA on the SPRINGFIELD network, you would need to grant access to SPRINGFIELD\\LISA$ to your database. 因此,如果您在SPRINGFIELD网络上使用名为LISA的IIS服务器,则需要向您的数据库授予对SPRINGFIELD \\ LISA $的访问权限。 Note the dollar sign which denotes your user as a machine account and not an actual person. 请注意美元符号,表示您的用户是机器帐户而非实际人员。

If your database server and your IIS server are one and the same, grant access to the account "NT AUTHORITY\\NETWORK SERVICE". 如果您的数据库服务器和IIS服务器是同一个,则授予对帐户“NT AUTHORITY \\ NETWORK SERVICE”的访问权限。 That's the whole name of the account. 这是帐户的全名。 And that should work. 那应该有用。

Are you running a non-english Operation System? 你在运行非英语操作系统吗?

For some reasons, the account name of "NT Authority\\Network Service" has been localized in other languages. 出于某些原因,“NT Authority \\ Network Service”的帐户名称已本地化为其他语言。
Sadly, a lot of programs have the account name hard coded to the english name, and won't find the Network Service when running on foreign versions of Windows. 遗憾的是,很多程序的帐户名称都硬编码为英文名称,并且在外国版本的Windows上运行时找不到网络服务。

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

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