Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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'.

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


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 ?
Posted
Updated 26-Feb-13 19:31pm
v3

1 solution

Though you created user2 but in connection string value of SqlConnection object you are using user1. So one way you can solve it like
SQL
GRANT select ON myTB TO use1


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.
 
Share this answer
 
Comments
Mohamad77 27-Feb-13 1:22am    
thanks for checking my problem.

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 ?
S. M. Ahasan Habib 27-Feb-13 1:38am    
You just logged in user2 instead of user1 and execute that query.
Mohamad77 27-Feb-13 1:45am    
when I logged in with user2 and tried this query: "GRANT select ON myTB TO user2",
I get this error instead:
Cannot find the object 'myTB', because it does not exist or you do not have permission.
S. M. Ahasan Habib 27-Feb-13 3:16am    
you can execute "GRANT select ON myTB TO user2" query from your sqlserver management studio. After that your application can access that table. Again that type of permission query, better you can execute inside database(enterprize manager) context.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900