Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8832219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:28:45+00:00 2026-06-14T08:28:45+00:00

I create new logins and user in my program like this(using sql stored procedures)

  • 0

I create new logins and user in my program like this(using sql stored procedures)

//new login
SqlCommand cmd = new SqlCommand("sp_addlogin", conn);
cmd.CommandType = CommandType.StoredProcedure;
string login = radTextBox2.Text;
string password = radTextBox3.Text;
cmd.Parameters.Add(new SqlParameter("@loginame", login));
cmd.Parameters.Add(new SqlParameter("@passwd", password));
int i = cmd.ExecuteNonQuery();
....
//new user
SqlCommand cmd = new SqlCommand("sp_adduser", conn);
cmd.CommandType = CommandType.StoredProcedure;
string username = radTextBox1.Text;
string role;
try
{
   switch (radDropDownList1.SelectedItem.Text)
   {
     case "Admin": { role = "db_owner"; break; }
     case "Guest": { role = "db_datareader"; break; }
     case "User": { role = "db_datawriter"; break; }
     default: { this.radLabelElement1.Text = "Role was not chosen!"; return; }
   }
 }
 catch (NullReferenceException) { this.radLabelElement1.Text = "Role was not chosen!"; return; };
 string login = radTextBox2.Text;
 cmd.Parameters.Add(new SqlParameter("@loginame", login));
 cmd.Parameters.Add(new SqlParameter("@name_in_db", username));
 cmd.Parameters.Add(new SqlParameter("@grpname", role));
 int result = cmd.ExecuteNonQuery();

because I want every user of database to have either all permissions in database for admin, only read permissions for guests and read/write/update/delete permission for user for all tables in database by default.

I thought if db_owner allowed to do everything in the database, then db_datawriter allowed to read/write/update/delete data in the database and db_datareader only can read data from database. But when I use login and password for user with db_datawriter role I’ve got an exception(when I try to view datagrid) – ‘the SELECT permission was denied on the object ‘Tablename’,database ‘Databasename’,schema ‘dbo’…On the other hand user with db_datareader role can see it but cant edit(so it works correct).

What’s the problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:28:46+00:00Added an answer on June 14, 2026 at 8:28 am

    If you want both read and write capabilities then they’ll need both db_datawriter and db_datareader roles. db_datawriter only grants write ability because there are use cases where you would want a user to be able to write to the database but not read from it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to test my successfully creates a new user after login (using authlogic).
i am new to smartGWT . i want to create auto login using j_security_check
I am new In ASP.NET, I want to create to Login Form using Membership
I am new to zend. I am trying to create login form using zend
I want to write a SQL 2005 script to create a new login that
I'm trying to create a generic login screen for Android. I'd like the program
I create a new login and user name while installing the db2 DBMS. After
I am new to Salesforce. I need to create a Login screen where users
Code to create new form instance of a closed form using form name I
I am trying to create a SQL database in c# by having my program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.