Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The SELECT permission was denied on the object '<Table_Name>', database '<Database_Name>', schema 'dbo'. - ASP.NET/SQL Server

I have a database "Sample". And there is a user in Active Directory (AD) called "CORPHQ\King". I have followed these steps:

1) Go to SQL Server Management Studio (2005) and "Security -> Logins".
2) Right Click -> New Login
3) Login Name : CORPHQ\King
4) Selected "Windows Authentication"
5) Default database - "Sample".
6) Under "User Mapping" section, Selected the "Sample" database, User as "CORPHQ\King" and selected "dbo" as default schema.
7) Selected "db_owner" as "Database role membership for - Sample".

Now in the WEB.CONFIG of the ASP.NET application, i do have:

<connectionStrings>
    <add name="DB" connectionString="Data Source=128.127.126.25; database=Sample; user=corphq\King; password=XXXXXXXXXXX; Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>
</connectionStrings>

Now when i ran the ASP.NET application, i am getting the error mentioned:

Error:

The SELECT permission was denied on the object 'tbl_Student', database 'Sample', schema 'dbo'

I think so user "CORPHQ\King" has the "db_owner" access to "Sample" database. Am i correct ? Where am i missing ?

Thanks

like image 886
user1054625 Avatar asked Dec 11 '12 22:12

user1054625


3 Answers

Since you're specifying Integrated Security in your connection string, you shouldn't be specifying a username and password when using Windows Authentication.

Instead, you will be authenticating as whatever domain account ASP.NET is running under, which is probably the network service account.

Your application is likely connecting as a totally different user than CORPHQ\King, and this other login doesn't have the permissions for this operation.

For more details, see How To: Connect to SQL Server Using Windows Authentication in ASP.NET 2.0

like image 91
Michael Fredrickson Avatar answered Oct 19 '22 18:10

Michael Fredrickson


You may have given it access to connect to the database, but there should be further steps to GRANT the user specific permissions such as SELECT, INSERT, UPDATE and DELETE on tables in that database.

like image 42
Adrian J. Moreno Avatar answered Oct 19 '22 19:10

Adrian J. Moreno


Solution is for this problem is that open the dbo schema Go to property and click on View database permission link. Give the database select ,delete edit permission to DOMAIN\MACHINENAME$. user.

like image 1
satish Avatar answered Oct 19 '22 18:10

satish