Cannot bulk load because the file "xxxxxxx.txt" could not be opened. Operating system error code 161(The specified path is invalid.).

ch-azure-sa 0 Reputation points
2024-09-04T04:41:13.28+00:00

I am trying to bulk insert to a azure SQL database table from the text file stored in BLOB storage.( It is a public storage

size of the file is 741MB

I did

CREATE EXTERNAL DATA SOURCE MyAzureBlobStorage

WITH ( TYPE = BLOB_STORAGE,

	LOCATION = 'https://xxxxxx.blob.core.windows.net/yyyyyyy/'

);

BULK INSERT database.schema.table

FROM 'xxxxxxx.txt'

WITH ( DATA_SOURCE = 'MyAzureBlobStorage',

	FIELDTERMINATOR = ',', 

ROWTERMINATOR = '\n' 

);

I am getting below error

Cannot bulk load because the file "xxxxxxx.txt" could not be opened. Operating system error code 161(The specified path is invalid.).

Could you please help me on this

Azure SQL Database
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,787 questions
{count} votes

1 answer

Sort by: Most helpful
  1. ShaktiSingh-MSFT 15,056 Reputation points
    2024-09-04T09:31:50.0866667+00:00

    Hi ch-azure-sa •,

    Welcome to Microsoft Q&A forum.

    As I understand, you are trying to bulk insert to a azure SQL database table from the text file stored in BLOB storage and getting error path invalid.

    Please make sure the file path is correct.

    Permissions are there to access path in Azure Blob Storage.

    DATA_SOURCE = 'data_source_name'

    Applies to: SQL Server 2017 (14.x) and Azure SQL Database.

    Specifies a named external data source pointing to the Azure Blob Storage location of the file that will be imported. The external data source must be created using the TYPE = BLOB_STORAGE option added in SQL Server 2017 (14.x). For more information, see CREATE EXTERNAL DATA SOURCE. For an example, see Import data from a file in Azure Blob Storage.

    Requests from Azure SQL Database using SAS tokens might be blocked with the following error:

    Msg 4861, Level 16, State 1, Line 27

    Cannot bulk load because the file "FileName.extension" could not be opened. Operating system error code 5(Access is denied.).

    Only a subset of Azure services are currently on the trusted services list. For a complete list of trusted services and updates on Azure storage firewall settings, see Trusted access for resources registered in your subscription.

    Refer examples here and try https://video2.skills-academy.com/en-us/sql/relational-databases/import-export/examples-of-bulk-access-to-data-in-azure-blob-storage?view=sql-server-ver16

    Let us know if this helps.

    Awaiting your reply.

    Thanks

    0 comments No comments

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.