Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL-Server WinForm
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();

 
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 26-Feb-13 19:47pm
Edited 26-Feb-13 20:31pm
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Though you created user2 but in connection string value of SqlConnection object you are using user1. So one way you can solve it like
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.
  Permalink  
Comments
Mohamad77 at 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 at 27-Feb-13 1:38am
   
You just logged in user2 instead of user1 and execute that query.
Mohamad77 at 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 at 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)

  Print Answers RSS
0 OriginalGriff 410
1 Jochen Arndt 200
2 Richard MacCutchan 135
3 DamithSL 105
4 PIEBALDconsult 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 27 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100