473,408 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

SQL 2000 Bulk Insert attempt on FTP in progress

Hi All,

I think this is a thorny problem, and I'm hoping you can help. I've not
found this exact issue described anywhere yet.

I have a stored procedure that calls BULK INSERT on a set of text files.
These files are FTP'd from a legacy system (a mainframe running MVS).
Sometimes, the process steps on iteslf, whereby the bulk insert is attempted
on a file whose FTP is still in progress; it's not fully written to disk on
the SQL box (it's a 100MB file that takes a long time to cross the network
to the share on the Windows box), and so the insert generates a fatal error
and the procedure stops.

I wrote a proc that calls the sp_OA* procs to use the
Scripting.FileSystemObject to test for the file's readiness. It returns an
error for me if the file does not exist. It also returns an error if I try
to run the BULK INSERT against a file which is being copied via Windows to
the SQL box. This is working just fine under those conditions; the
sp_OAMethod to call OpenTextFile bombs appropriately if the file write is
still in progress.

That's great, but it doesn't do the same thing during an FTP in progress.
It doesn't generate the same error (that is OpenTextFile has no problem
opening a partially written FTP'd file). I can also open the file in
Notepad, even though it's not fully written to disk ... something I did not
expect, but there we are. What is it about FTP that's different from a
Windows file system copy operation that makes the file look available for
reading?

If BULK INSERT is capable of detecting that it cannot do its thing on a file
whose FTP is in progress, then what can I write or call to emulate that
detection? I tried writing a COM object in VB.NET and calling that from my
SQL stored proc instead of the Scripting Engine's FSO methods. My code
simlpy tries to run a FileOpen using an Exclusive read lock; however, this
doesn't seem to work, and I'm shooting in the dark now.

Can anyone tell me what kind of file i/o request BULK INSERT makes, such
that it is capable of abending during a run against an incompletely written
file using FTP?

Thanks!
Tim
Dec 6 '06 #1
3 3435
Tim Satterwhite wrote:
Hi All,

I think this is a thorny problem, and I'm hoping you can help. I've not
found this exact issue described anywhere yet.

I have a stored procedure that calls BULK INSERT on a set of text files.
These files are FTP'd from a legacy system (a mainframe running MVS).
Sometimes, the process steps on iteslf, whereby the bulk insert is attempted
on a file whose FTP is still in progress; it's not fully written to disk on
the SQL box (it's a 100MB file that takes a long time to cross the network
to the share on the Windows box), and so the insert generates a fatal error
and the procedure stops.

I wrote a proc that calls the sp_OA* procs to use the
Scripting.FileSystemObject to test for the file's readiness. It returns an
error for me if the file does not exist. It also returns an error if I try
to run the BULK INSERT against a file which is being copied via Windows to
the SQL box. This is working just fine under those conditions; the
sp_OAMethod to call OpenTextFile bombs appropriately if the file write is
still in progress.

That's great, but it doesn't do the same thing during an FTP in progress.
It doesn't generate the same error (that is OpenTextFile has no problem
opening a partially written FTP'd file). I can also open the file in
Notepad, even though it's not fully written to disk ... something I did not
expect, but there we are. What is it about FTP that's different from a
Windows file system copy operation that makes the file look available for
reading?

If BULK INSERT is capable of detecting that it cannot do its thing on a file
whose FTP is in progress, then what can I write or call to emulate that
detection? I tried writing a COM object in VB.NET and calling that from my
SQL stored proc instead of the Scripting Engine's FSO methods. My code
simlpy tries to run a FileOpen using an Exclusive read lock; however, this
doesn't seem to work, and I'm shooting in the dark now.

Can anyone tell me what kind of file i/o request BULK INSERT makes, such
that it is capable of abending during a run against an incompletely written
file using FTP?

Thanks!
Tim

Can your FTP routine move the file(s) to another directory once it
completes an upload? This would seem easier than the above. Am I
missing something that prevents this possibility?
Dec 7 '06 #2
The approach we used was that along with every set of files that were
FTPed, one extra file was transfered after all the rest were done. The
presence of that flag file indicated that the set of data was
complete; THAT was the file the load process waited for. Once the BCP
steps for the data files were done, the flag file was deleted, and the
wait for the next flag file began over again.

Roy Harvey
Beacon Falls, CT

On Wed, 6 Dec 2006 14:55:18 -0800, "Tim Satterwhite"
<ti*****************@nospamucsfmedctr.orgwrote:
>Hi All,

I think this is a thorny problem, and I'm hoping you can help. I've not
found this exact issue described anywhere yet.

I have a stored procedure that calls BULK INSERT on a set of text files.
These files are FTP'd from a legacy system (a mainframe running MVS).
Sometimes, the process steps on iteslf, whereby the bulk insert is attempted
on a file whose FTP is still in progress; it's not fully written to disk on
the SQL box (it's a 100MB file that takes a long time to cross the network
to the share on the Windows box), and so the insert generates a fatal error
and the procedure stops.

I wrote a proc that calls the sp_OA* procs to use the
Scripting.FileSystemObject to test for the file's readiness. It returns an
error for me if the file does not exist. It also returns an error if I try
to run the BULK INSERT against a file which is being copied via Windows to
the SQL box. This is working just fine under those conditions; the
sp_OAMethod to call OpenTextFile bombs appropriately if the file write is
still in progress.

That's great, but it doesn't do the same thing during an FTP in progress.
It doesn't generate the same error (that is OpenTextFile has no problem
opening a partially written FTP'd file). I can also open the file in
Notepad, even though it's not fully written to disk ... something I did not
expect, but there we are. What is it about FTP that's different from a
Windows file system copy operation that makes the file look available for
reading?

If BULK INSERT is capable of detecting that it cannot do its thing on a file
whose FTP is in progress, then what can I write or call to emulate that
detection? I tried writing a COM object in VB.NET and calling that from my
SQL stored proc instead of the Scripting Engine's FSO methods. My code
simlpy tries to run a FileOpen using an Exclusive read lock; however, this
doesn't seem to work, and I'm shooting in the dark now.

Can anyone tell me what kind of file i/o request BULK INSERT makes, such
that it is capable of abending during a run against an incompletely written
file using FTP?

Thanks!
Tim
Dec 7 '06 #3
Hi folks,

Thanks for your suggestions. A group of people I know gave this some
thought, and two posed the option that I write a loop which compares the
FTP'd file's size to itself every few seconds. When the file size stops
growing, I can reasonably guess that the write is complete. I wrote such a
procedure in T-SQL today, and it seems to work in my testing scenarios.

In response to Roy, I'd love to have an end of job file sent, but I need to
process files as soon as they arrive. If I wait for all the files (I'm
contending with 500 files over a 45 minute period), then I'm inconveniencing
my customers. An EOJ file for each data file would inconvenience the COBOL
programmer who is sending all this data from the mainframe. I can start my
import process and pause for individual files that are in contention with
SQL Server, though.

In response to Jonathan, we can (and do) move the (older) files to another
directory after upload, but my problem is that I can't upload if the current
day's file happens to be writing while the upload process is focusing on
that file during its loop through the list of files to expect.

Again, I think I might have nailed this by comparing file sizes over time.
I'll know when I move my code to production next week. I appreciate your
guys' time and energy!!!!

Regards,
Tim

"Tim Satterwhite" <ti*****************@nospamucsfmedctr.orgwrote in
message news:el***********@itssrv1.ucsf.edu...
Hi All,

I think this is a thorny problem, and I'm hoping you can help. I've not
found this exact issue described anywhere yet.

I have a stored procedure that calls BULK INSERT on a set of text files.
These files are FTP'd from a legacy system (a mainframe running MVS).
Sometimes, the process steps on iteslf, whereby the bulk insert is
attempted
on a file whose FTP is still in progress; it's not fully written to disk
on
the SQL box (it's a 100MB file that takes a long time to cross the network
to the share on the Windows box), and so the insert generates a fatal
error
and the procedure stops.

I wrote a proc that calls the sp_OA* procs to use the
Scripting.FileSystemObject to test for the file's readiness. It returns
an
error for me if the file does not exist. It also returns an error if I
try
to run the BULK INSERT against a file which is being copied via Windows to
the SQL box. This is working just fine under those conditions; the
sp_OAMethod to call OpenTextFile bombs appropriately if the file write is
still in progress.

That's great, but it doesn't do the same thing during an FTP in progress.
It doesn't generate the same error (that is OpenTextFile has no problem
opening a partially written FTP'd file). I can also open the file in
Notepad, even though it's not fully written to disk ... something I did
not
expect, but there we are. What is it about FTP that's different from a
Windows file system copy operation that makes the file look available for
reading?

If BULK INSERT is capable of detecting that it cannot do its thing on a
file
whose FTP is in progress, then what can I write or call to emulate that
detection? I tried writing a COM object in VB.NET and calling that from
my
SQL stored proc instead of the Scripting Engine's FSO methods. My code
simlpy tries to run a FileOpen using an Exclusive read lock; however, this
doesn't seem to work, and I'm shooting in the dark now.

Can anyone tell me what kind of file i/o request BULK INSERT makes, such
that it is capable of abending during a run against an incompletely
written
file using FTP?

Thanks!
Tim


Dec 8 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: php newbie | last post by:
Hello, I am trying to load a simple tab-delimited data file to SQL Server. I created a format file to go with it, since the data file differs from the destination table in number of columns. ...
7
by: iqbal | last post by:
Hi all, We have an application through which we are bulk inserting rows into a view. The definition of the view is such that it selects columns from a table on a remote server. I have added the...
1
by: joshsackett | last post by:
Hello all, I have a multiple text files with an odd row terminator. If you were to examine it in VB it would be like a "CrCrLf" instead of just "CrLf". In HEX it is DDA instead of just DA. When I...
6
by: pk | last post by:
Sorry for the piece-by-piece nature of this post, I moved it from a dormant group to this one and it was 3 separate posts in the other group. Anyway... I'm trying to bulk insert a text file of...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
3
by: moonriver | last post by:
Right now I develop an application to retrieve over 30,000 records from a binary file and then load them into a SQL Server DB. So far I load those records one by one, but the performance is very...
5
by: JSParker1 | last post by:
Summary: Maximum number of records per second that can be inserted into SQLServer 2000. I am trying to insert hundreds (preferably even thousands) of records per second in to SQLServer table...
0
by: ozkhillscovington | last post by:
We have sp's in place that do BULK INSERTS from txt files into the tables. This works fine, however they have asked us to add a field that identifies accounting ctr. The only thing that identifies...
0
by: debug03 | last post by:
I am executing a DTS package on a Windows 2000 sp4 server running SQL Server 2000 and IBM DB2 V7 client. The DTS package source data(SQL Server) is selected from SQL server table and inserts data to...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.