Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Please help me. I m getting the error but not in code. While i run that page it shows an error like this
"INSERT permission denied on object 'employeeinfm', database 'samp', schema 'dbo'."
What is the cause of this error.
Please suggest a solution for this..

C#
try
{
    cmd = new SqlCommand("insert into employeeinfm values (@employeeid,@employeename,@designation,@password,@confirmpwd)", cn);

    cmd.Parameters.Add("@employeeid", SqlDbType.NVarChar, 50)
                   .Value = Txtempid.Text;
    cmd.Parameters.Add("@employeename", SqlDbType.NVarChar, 50)
                   .Value = Txtename.Text;
    cmd.Parameters.Add("@designation", SqlDbType.NVarChar, 50)
                   .Value = Txtdesig.Text;
    cmd.Parameters.Add("@password", SqlDbType.NVarChar, 50)
                   .Value = Txtpwd.Text;
    cmd.Parameters.Add("@confirmpwd", SqlDbType.NVarChar, 50)
                   .Value = Txtconfirmpwd.Text;

    cn.Open();
    cmd.ExecuteNonQuery();
    Label7.Text = "Saved successfully!";
    cn.Close();
}
catch (Exception ex)
{
    Response.Write(ex.Message);
}


Thanks in advance
Ramya.P
email:ramyaponnuswami@gmail.com
Posted
Updated 21-Sep-11 19:52pm
v2
Comments
[no name] 22-Sep-11 2:10am    
this database is on live server for web application?

That's because the user you're connected with to the SQL Server does not have permission to insert into your employeeinfm table.

To grant permissions to a user see http://msdn.microsoft.com/en-us/library/ms186717.aspx[^]
 
Share this answer
 
Comments
Mehdi Gholam 22-Sep-11 1:56am    
Just posted the same, my 5!
Simon Bang Terkildsen 22-Sep-11 2:44am    
Thank you, Mehdi. Great minds think alike :)
Mehdi Gholam 22-Sep-11 2:46am    
My mind is not so great :)
Simon Bang Terkildsen 22-Sep-11 2:49am    
hmm I think you just insulted me :P
Mehdi Gholam 22-Sep-11 2:57am    
Just commenting on my own state of mind! No offense!
The user used to connect to the database does not have permissions to insert into the employeeinfm table.

GRANT permissions for that user.
 
Share this answer
 
Hi,

Please check the schema for employeeinfm table. When we create table the default schema will be dbo, but in many cases when we upload such database to live server at that time default schema will be changed like username will be default schema
E.g.

dbo.employeeinfm [before]
samp.employeeinfm [after]


so, please check that. If it is dbo then you need the write permission for that user.
 
Share this answer
 
Comments
Simon Bang Terkildsen 22-Sep-11 2:47am    
You make a good point to keep in mind, however here the schema is dbo as you can read from the exception message. also it wouldn't be dbo.employeeinfm but dbo.samp.employeeinfm
[no name] 22-Sep-11 3:50am    
Thank you :) Simon Bang Terkildsen

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