Getting an Access Denied error when accessing a file in Azure Blob Storage

IAA Dashboard 0 Reputation points
2025-05-30T17:00:14.79+00:00

Files have been loaded into a blob container, and through PowerShell, that data has been loaded into the Azure SQL database successfully for over 2 years. As of last week, this process was functioning correctly.

Currently encountering an Access Denied error:

Error merging 2025-04-05 00:00:00: ('42000', '[42000] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Cannot bulk load because the file "brandong2/docs-20250405 - US.json" could not be opened. Operating system error code 5(Access is denied.). (4861) (SQLExecDirectW)')

Despite checking permissions, nothing appears to have changed. Seeking options that may have been overlooked.

Azure SQL Database
{count} votes

2 answers

Sort by: Most helpful
  1. Ovidiu Cif 0 Reputation points
    2025-05-30T20:38:55.6033333+00:00

    Hi @IAA Dashboard here are a few things that might be worth re-checking (sometimes the root cause isn’t immediately apparent):

    1. make sure the account running the SQL Server service has explicit read access to both the file and its parent directory. The permissions needed are for the SQL service account, not your personal account
    2. If you’re using a local or network path, verify that the file is accessible from the SQL Server machine and that the path hasn’t changed. If you're accessing an Azure Blob, ensure any SAS tokens, access keys, or managed identity permissions are still valid and haven't expired or been rotated
    3. if there have been any recent updates to OS, group policy, antivirus, or firewall rules that might be affecting access
    4. the file isn’t open or being used by another process, which can sometimes cause access errors
    5. Make sure the SQL login being used has the necessary bulk operations permissions
    6. If this is running against Azure SQL Database (not SQL Server in a VM), direct file system access isn’t supported—use external data sources and make sure your authentication method is still valid
    0 comments No comments

  2. Narendra Pakkirigari 475 Reputation points Microsoft External Staff Moderator
    2025-06-16T08:29:55.45+00:00

    Hi @IAA Dashboard,

    The "Access is Denied" error (Operating system error code 5) you're encountering during the BULK INSERT operation from Azure Blob Storage into Azure SQL Database is most commonly caused by either firewall restrictions on the storage account or issues with the credentials used to access the blob. One of the first things to check is the firewall configuration on your Azure Storage Account. In the Azure Portal, go to the storage account’s Networking section and verify that public network access is enabled. For troubleshooting, set it temporarily to allow access from all networks. If the setting restricts access to selected networks and the Azure SQL Database is not explicitly allowed, the database won’t be able to reach the blob, resulting in the access denied error.

    You mentioned that files have been successfully loaded into Azure SQL from blob storage using PowerShell for over 2 years, and the process only recently started failing. This strongly suggests a change in the storage account’s network settings, token expiry, or a rotation of storage keys that may have gone unnoticed.

    Next, verify that the external data source used in your BULK INSERT statement is configured correctly with a valid Shared Access Signature (SAS) token or Storage Account Key. If you're using a SAS token, make sure it has not expired and contains the appropriate permissions at minimum, read(r) and list (l). Also, ensure the file path is accurate, including correct casing and the exact folder structure, since blob paths are case-sensitive.

    It’s also important to clarify that adding the database name in the INSERT INTO clause of your BULK INSERT statement, as suggested in a previous response, is unnecessary and unrelated to this specific error. The problem is not with SQL syntax but rather with file access. Additionally, the suggested syntax (insert into ... from 'file.csv' with (...)) is incorrect. The proper syntax is:

    BULK INSERT schema.table FROM 'filename' WITH (DATA_SOURCE = 'source_name', ...);

    If you’ve already found a solution to this problem, we encourage you to share it with the community. Your experience could help others facing a similar issue.

    If anything is unclear or if you need further help, feel free to add a comment below.

    Also, please click “Accept Answer” if this helped, so others can find the solution more easily.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.