Troubleshooting Guide: Error 5358 – ERRORFILELOCATION Cannot Be Specified Without ERRORFILEDATA_SOURCE
Why This Error Happens
This error occurs when a BULK INSERT or OPENROWSET(BULK...) command specifies the ERRORFILE or ERRORFILE_LOCATION parameter without pairing it with a required ERRORFILE_DATA_SOURCE argument. SQL Server 2025 enforces stricter syntax validation for bulk import operations, requiring that any error logging path be tied to an explicitly defined external data source object rather than a raw file path. Essentially, the engine does not know where (which credential/endpoint) to write the error file because the physical path lacks a corresponding logical data source reference.
Step-by-Step Resolution Guide
Step 1: Verify the Current Bulk Insert Syntax
- Open SQL Server Management Studio (SSMS) 21 or Azure Data Studio connected to your SQL Server 2025 instance.
- Locate the specific
BULK INSERTorOPENROWSETstatement throwing Error 5358. - Check if
ERRORFILE = 'path'is present without an accompanyingERRORFILE_DATA_SOURCEclause.
Step 2: Create an External Data Source Object
- Run the following T-SQL to define a data source pointing to your error log container or network share:
CREATE EXTERNAL DATA SOURCE MyErrorLogSource
WITH (
TYPE = BLOB_STORAGE,
LOCATION = 'https://yourstorageaccount.blob.core.windows.net/errorlogs'
);
- If using a local file path instead of Azure Blob Storage, ensure you are referencing a valid Windows Server 2025 file share with a
CREDENTIALobject attached if authentication is required.
Step 3: Update the Bulk Insert Command
- Modify your original script to explicitly include the
ERRORFILE_DATA_SOURCEargument alongsideERRORFILE_LOCATION:
BULK INSERT dbo.YourTable
FROM 'data/importfile.csv'
WITH (
DATA_SOURCE = 'MyDataSource',
ERRORFILE_LOCATION = 'errors/import_errors.log',
ERRORFILE_DATA_SOURCE = 'MyErrorLogSource'
);
- Ensure the SQL Server Service Account (e.g.,
NT Service\MSSQLSERVER) has write permissions to the target error log directory if using local storage.
Step 4: Validate File System Permissions
- Navigate to
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\or your custom error log directory in Windows Server 2025. - Right-click the folder, select Properties > Security, and confirm the SQL Server service account has Write and Modify permissions.
- Restart the SQL Server service via
services.mscif permissions were just updated.
Alternative or Verification Steps
- Re-run the
BULK INSERTcommand and check the designated error file path to confirm the log file is generated successfully upon a forced bad-row import. - If the error persists, use
sys.external_data_sourcesto query and confirm the data source object exists and is correctly linked:SELECT * FROM sys.external_data_sources;