Access Denied when inserting file into Sql Server 2012 FileTable using File.CreateFile in ASP.NET website

懵懂的女人 提交于 2019-11-28 13:52:06

This is a permissions problem. However, the permissions are not granted through NTFS but through SQL Server.

The Application Pool Identity does not have any permissions on your database by default so this has to be changed.

  1. Add a Login to SQL Server for the Application Pool Identity you are using for your website. E.g. "IIS APPPool\MyAppPool"

    USE [master]
    GO
    CREATE LOGIN [IIS APPPOOL\myapppoolname] FROM WINDOWS WITH DEFAULT_DATABASE=[MyDatabase]
    GO
    
  2. Add a User to your database that this login will use

    USE [MyDatabase]
    CREATE USER [MyUserName] FOR LOGIN [IIS APPPool\myapppoolname]
    
  3. Grant the user relevant permissions on your database

    use [MyDatabase]
    GRANT INSERT TO [MyUserName]
    GRANT SELECT TO [MyUserName]
    GRANT UPDATE TO [MyUserName]
    

I'm not sure if this is the complete set of permissions required but I found it was sufficient for me to be able to save a new file.

The accpted answer did not work for me. The answer in this link did.

My IIS server was not on the same server as the sql database, so I had to make sure that the application pool user for IIS existed as a windows user on the sql server, that they had the same password and that there is a sql windows user for the account.

Justin

I had the same issue. The following answer works for me.

  1. Create a new account on both servers with the same password.
  2. Configure that account to run your IIS app
  3. Create a login in SQL Server for that account with the appropriate rights.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!