简体   繁体   中英

How to correct 'Operating system error code 12007' when accessing Azure blob storage in a SQL stored procedure

I'm trying to create a stored procedure that will access a file in an azure blob storage container, store the first line of the file in a temporary file, use this data to create a table (effectively using the header fields in the file as the column titles), and then populate the file with the rest of the data.

I've tried the basic process in a local SQL database, using a local source file on my machine, and the procedure itself works as I want it to, creating a new table from the supplied file.

However, when I've set it up within an Azure SQL database and amend the procedure to use a 'datasource' rather than pointing it at a local file, it's producing the following error:

 Cannot bulk load because the file "my_example_file" could not be opened. Operating system error code 12007(failed to retrieve text for this error. Reason: 317).

My stored procedure contains the following:

 CREATE TABLE [TempColumnTitleTable] ([ColumnTitles] [nvarchar](max)
 NULL);
 DECLARE @Sql NVARCHAR(Max) = 'BULK INSERT [dbo].   
 [TempColumnTitleTable]     FROM ''' + @fileName + ''' WITH
 (DATA_SOURCE     = ''Source_File_Blob'', DATAFILETYPE = ''char'', 
 FIRSTROW = 1, LASTROW =     1,     ROWTERMINATOR = ''0x0a'')';
 EXEC(@Sql);

The above should be creating a single column table containing all the text for the headers, which I can then interrogate and use for the column titles in my permanent file. I've set up the DataSource as follows:

 CREATE EXTERNAL DATA SOURCE Source_File_Blob
 WITH ( 
 TYPE       = BLOB_STORAGE,
 LOCATION   = 'location_url',
 CREDENTIAL = AzureBlobCredential
 );

with an appropriate credential in place!

I'm expecting it to populate my temporary column title file (and then go on and do the other populating that I haven't shown code for above), but it just returns the mentioned error code.

I've had a Google, but the error code seems to be related to other 'path' type issues that I don't think apply here.

We've got similar processes that use blob storage with the same credentials, and they all seem to work ok, but the problem is that the person who wrote them is no longer at our company, so I can't actually consult them!

So basically, what would be causing that error? I don't think it's access, since I am able to run similar processes on other blobs, and as far as I can tell access levels are the same on these.

Yep - used the wrong URL as prefix. It was only when I was finally got access to the blob storage that I realised.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM