本文介绍了Sql用户改变问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们。



我在我的服务器上创建了一个DataBase然后是一个表:DB1和myTB。

我被记录了在user1中。我的意思是创建过程由user1完成。



user1可以执行任何查询,例如从myTB中选择*



我创建了另一个用户:user2(我无法访问用户属性!服务器只允许我创建新用户而无需更改用户属性的选项! )



现在当我执行上面提到的相同查询时,我在第2行收到此错误消息(cmd.Exe ...)



错误消息:无效的对象名称''myTB''。



Hi friends.

I have created a DataBase and then a Table on my server: DB1 and myTB.
I was logged in by user1. I mean the creating process was done by user1.

user1 can execute any query such as "Select * from myTB".

I have created another user: user2 ( I don''t have access to user properties ! the server just allow me to create new user with no more option to change user properties ! )

now when I execute the same query I''ve mentioned above, I get this error message on line 2 (cmd.Exe... )

Error msg: Invalid object name ''myTB''.

cmd = new SqlCommand("Select * from myTB", con);
cmd.ExecuteNonQuery();





所以在我看来,也许我应该给user2适当的权限。如果是这样,怎么样?

记住我可以执行查询。我的意思是我应该通过sql-queries解决问题!



我试过这样的事:

GRANT选择ON myTB对用户2



但问题出现了!



SQL SERVER 2005



我将不胜感激任何帮助。

感谢advande。





1.我已经用user1登录,然后创建db和table(现在user1是我认为的所有者!)

2.我创建了另一个名为user2的用户。 br />
3.我的问题是user2无法对user1创建的数据库和表执行任何查询(user2 CAN连接到我的数据库)

4.所以,到解决问题,我已经通过user1登录并尝试了这个查询:GRANT选择ON myTB TO user2以向user2授予选择权限。



什么第四步错了吗?我应该更改任何用户吗?



so in my opinion, maybe I should give the proper permissions to user2. if so, HOW ?
remember that I can just execute query. I mean I should solve the problem just by sql-queries !

I''ve tried sth like this:
GRANT select ON myTB TO user2

but the problem is on !

SQL SERVER 2005

I''ll appreciate any help.
thanks in advande.


1. I''ve logged in with user1, then create db and table (now user1 is the owner I think !)
2. I''ve created another user named user2.
3. my problem is user2 can''t execute any query on the db and table that created by user1 ( user2 CAN connect to my database )
4. so, to solve the problem, I''ve logged in by user1 and tried this query:"GRANT select ON myTB TO user2" to grant the select permission to user2.

what was wrong with 4th step ? should I change any user ?

推荐答案

GRANT select ON myTB TO use1





只需将grant语句从user2更改为user1即可。因为在您的应用程序中您没有使用user2,否则您可以更改连接字符串值并将user2设置为替换user1。



Just change in your grant statement from user2 to user1. Because in your application you are not using user2 otherwise you can change your connection string value and set user2 in replace of user1.


这篇关于Sql用户改变问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 12:07