SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Bulk Insert using UNC path of a Filetable Directory


Bulk Insert using UNC path of a Filetable Directory

Author
Message
Louis Albrant
Louis Albrant
SSC Rookie
SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)

Group: General Forum Members
Points: 32 Visits: 37
Erland,

I decided to try your approach and in the preliminary tests the results are better than I expected.

A simplified version of my script is as follows:

--Beginning of sample script---

DECLARE @File_Content varchar(MAX), @Delimiter varchar(10)

SET @Delimiter = CHAR(10)

SELECT @File_Content = (convert(varchar(MAX), file_stream))
FROM [dbo].[FileTableTb]

INSERT INTO vw_File_Load
SELECT file_record
FROM [dbo].[udf_text_list_to_tbl](@File_Content, @Delimiter)

--End of Sample Script---

-----Function (modified slightly from your website page)-------

CREATE FUNCTION udf_text_list_to_tbl (@list varchar(MAX), @Delimiter varchar(10))
RETURNS @tbl TABLE (file_record varchar(MAX) NOT NULL) AS
BEGIN
DECLARE @pos int,
@nextpos int,
@valuelen int

SELECT @pos = 0, @nextpos = 1

WHILE @nextpos > 0
BEGIN
SELECT @nextpos = charindex(@Delimiter, @list, @pos + 1)
SELECT @valuelen = CASE WHEN @nextpos > 0
THEN @nextpos
ELSE len(@list) + 1
END - @pos - 1
INSERT @tbl (file_record)
VALUES (substring(@list, @pos + 1, @valuelen))
SELECT @pos = @nextpos
END
RETURN
END

--End of Function-----

Numbers for comparison:

File size - 406,243 KB
Records - 838,695

Timings:

BULK LOAD - 1 minute 9 seconds
SAMPLE SCRIPT - 1 minute 33 seconds

In conclusion, your method simplifies the security model for the application and is cleaner than my work around. While a little slower, I am going to give it a try.

Thanks for your assistance.

Louis
Erland Sommarskog
Erland Sommarskog
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2181 Visits: 872
That's great to hear. Note that the article suggests other alternatives that are faster than the simple version you tried.

Erland Sommarskog, SQL Server MVP, www.sommarskog.se
DanMcClain
DanMcClain
SSC Journeyman
SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)SSC Journeyman (79 reputation)

Group: General Forum Members
Points: 79 Visits: 578
Lewis, did you ever achieve a resolution for this? I have bumped into the same issue, and only work around is to move files to alternate location or BCP.



Dan Guzman-481633
Dan Guzman-481633
SSC Veteran
SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)SSC Veteran (216 reputation)

Group: General Forum Members
Points: 216 Visits: 394
File tables don't allow local memory-mapped file access, which may explain the "request is not supported" error with BULK INSERT. I would expect a technique that performs the bulk insert remotely (e.g. BCP, SISS, etc.) will avoid this restriction with file tables.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search