开发者

SQL Server Network Service as dbo

I have SQL Server 2005 running on Windows Server 2003. I noticed that when I query the server from my web app (IIS 6.0 running app pool with Network Service) with a command containing "SELECT USER_NAME()", I get "dbo" instead of "NT AUTHORITY\NETWORK SERVICE". I don't even have the NETWORK SER开发者_Python百科VICE running as dbo on my database.

How do I prevent NETWORK SERVICE running as dbo on my database?

As a side note, I ran the same code and database on my PC with Windows 7 (IIS 7), SQL Server 2008, and it returned the "SELECT USER_NAME()" as "NT AUTHORITY\NETWORK SERVICE" which is exactly what I expect. What gives?

Edit:Sorry I didn't make changes to this post instead. I'm new at this. As I was saying, the original login was indeed network service and it's accessing the database as dbo which I didn't expect. The network service account didn't have sysadmin role or db_owner for the database. However, I looked up it's effective permissions and it's similar to that of a sysadmin. I made sure that network service isn't part of the local administrator group and it's not running the SQL server service itself. Looking up google for answers, I did come across someone with similar situation and they ended up querying the sys.login_token when running as the app to see what principal role it's giving the network service permission. Anyway, it's late Friday and I'm gonna have to continue Monday. Cheers!


If you want to verify the actual login name then use system_user or suser_sname()

From books online regarding user_name():

*If a Windows principal accesses the database by way of membership in a group, USER_NAME returns the name of the Windows principal instead of the group.*

Regarding the second part of your question, keeping it from running as dbo...

Read up on the definition of dbo here, but in short anything that is a sysadmin on your instance is going to be a dbo.


It returns "dbo" on most of the servers I tried.

On one server it returned "guest".

Check this out.

http://msdn.microsoft.com/en-us/library/ms188014.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜