2

I try to SELECT some data from SQL Server via my ASP.NET MVC web-app which is hosted in a Local IIS 7 and I'm getting this error:

System.Data.SqlClient.SqlException: The SELECT permission was denied on object 'tableName', database 'dbName', schema 'dbo'.

Knowing that all the IIS APPPOOL\ASP.NET V4.0 Integrated's privileges are checked, how do I to fix this, please?

Stack trace:

[RuntimeBinderException: Cannot perform runtime binding on a null reference] CallSite.Target(Closure , CallSite , Object ) +200
System.Dynamic.UpdateDelegates.UpdateAndExecute1(CallSite site, T0 arg0) +924 ASP._Page_Views_Shared__Header_cshtml.Execute() in c:\Users\Nectarys\desktop\monitoringn_web\monitoring2 - copy\monitoringn\Views\Shared_Header.cshtml:11
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +126
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +196
System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData) +158 ASP._Page_Views_Shared__Layout_cshtml.Execute() in c:\Users\Nectarys\desktop\monitoringn_web\monitoring2 - copy\monitoringn\Views\Shared_Layout.cshtml:13
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +126
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +196
System.Web.WebPages.WebPageBase.Write(HelperResult result) +89
System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action1 body) +233
System.Web.WebPages.WebPageBase.PopContext() +291
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +378 System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +33 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func
1 continuation) +855148 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +265
System.Web.Mvc.Async.<>c_DisplayClass25.b_22(IAsyncResult asyncResult) +839620
System.Web.Mvc.<>c_DisplayClass1d.b_18(IAsyncResult asyncResult) +28
System.Web.Mvc.Async.<>c_DisplayClass4.b_3(IAsyncResult ar) +15 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +65
System.Web.Mvc.Async.<>c_DisplayClass4.b_3(IAsyncResult ar) +15 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +51
System.Web.Mvc.<>c_DisplayClass8.b_3(IAsyncResult asyncResult) +42
System.Web.Mvc.Async.<>c_DisplayClass4.b_3(IAsyncResult ar) +15 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +51
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288

Also, I've grant SELECT,INSERT,UPDATE,DELETE on dbo.tableName to "IIS APPPOOL\ASP.NET V4.0 Integrated";. I've did this by selecting the dbName and making in new script in which I've written that line.

2 Answers 2

3

Your db user do not have rights to read from table's in db. You can give it db_owner rights and it should work.

  1. Login to SQL server
  2. Go to your database --> expand it
  3. Security--> your db user
  4. Right Click--> properties
  5. Make sure that db_owner is selected
2
  • good thought making it dbowner narrow down to exact problem. of course later one can set relevant required permission.
    – user991513
    Commented Aug 26, 2016 at 15:12
  • db_owner is an elevated privilege you shouldn't be using unless the user is responsible for creating or maintaining database schema. Use the db_datareader and db_datawriter database roles instead, that should be granted the necessary privileges.
    – Suncat2000
    Commented Dec 8, 2022 at 15:41
0

I had a different issue. I already had done changing permissions to 'db_owner', but it still didn't fix my problem. Then I changed DefaultAppPool to 'NetworkService' in IIS Manager. It fixed my issue.

Not the answer you're looking for? Browse other questions tagged or ask your own question.