Windows 10: Fix: BEGIN TRY does not work with BULK INSERT on SQL

Discus and support Fix: BEGIN TRY does not work with BULK INSERT on SQL in Windows 10 Tutorials to solve the problem; I have created a stored procedure that does a BULK IMPORT. I wanted to add a bit of fault checking and added a BEGIN TRY and a BEGIN CATCH so that it... Discussion in 'Windows 10 Tutorials' started by Noel, Jun 21, 2018.

  1. Noel New Member

    Fix: BEGIN TRY does not work with BULK INSERT on SQL


    I have created a stored procedure that does a BULK IMPORT. I wanted to add a bit of fault checking and added a BEGIN TRY and a BEGIN CATCH so that it sends an email with the error message if the T-SQL fails. The problem is that the BEGIN CATCH was being skipped and the procedure stops processing with the below error message.

    Msg 4860, Level 16, State 1, Line 2
    Cannot bulk load. The file "C:\temp\fileimport.txt" does not exist.

    To fix the issue what I did is to add the BULK INSERT command in a variable and execute it. This way, the BEGIN CATCH is not ignored or skipped.

    Fix below

    BEGIN TRY
    DECLARE @bulkimport varchar(1000)
    SET @bulkimport = 'BULK INSERT mytable FROM ''C:\temp\fileimport.txt''
    WITH (FIELDTERMINATOR = ''*'', ROWTERMINATOR = ''\n'')'
    EXECUTE (@bulkimport)
    END TRY

    BEGIN CATCH
    SELECT error_message()
    END CATCH

    (41)

    read more...
     
  2. ap1978 Win User

    Bulk Crap Uninstaller 4.3.4


    • Added capability to open update link in web browser
    • Fixed treemap not working correctly with only 1 item on the list
    • Blacklisted "Installer" folder for drive scanning
    • Relaxed overly strict check for questionable directory names
    • Updated rate link to a new website

    Klocman/Bulk-Crap-Uninstaller
    https://github.com/Klocman/Bulk-Crap...ses/tag/v4.3.4
     
    ap1978, Jun 21, 2018
    #2
  3. suraswami Win User
    SQL Question

    Its been a while since I wrote any advanced sql code, here is the statement if it was M$ SQL Server

    MERGE services.corproster corp
    USING (SELECT name FROM seat.corporation_member_tracking)
    AS JoinResult
    ON (corp.name = JoinResult.name)
    WHEN MATCHED AND ISNULL(corp.name, '') <> ISNULL(JoinResult.name, '')
    THEN UPDATE SET corp.name = JoinResult.name
    WHEN NOT MATCHED THEN
    INSERT name VALUES JoinResult.name
    ;

    OR may be try this

    BEGIN TRANSACTION
    UPDATE corp
    set corp.name = source.name
    from services.corproster corp join seat.corporation_member_tracking source
    ON corp.name = source.name
    INSERT INTO services.corproster (name)
    SELECT name FROM seat.corporation_member_tracking
    where name not in (select name from services.corproster)
    COMMIT TRANSACTION

    I would only delete and insert if the table has less rows
     
    suraswami, Jun 21, 2018
    #3
  4. zbook Win User

    Fix: BEGIN TRY does not work with BULK INSERT on SQL

    Programs not working


    In post 26 there were steps listed to fix the operating system corruption.
    Are you able to follow them?
    In post 29 was the suggested dism repair command.
     
    zbook, Jun 21, 2018
    #4
    1 person likes this.
Thema:

Fix: BEGIN TRY does not work with BULK INSERT on SQL

Loading...
  1. Fix: BEGIN TRY does not work with BULK INSERT on SQL - Similar Threads - Fix BEGIN TRY

  2. Fixed: Hibernate does not work

    in Windows 10 Gaming
    Fixed: Hibernate does not work: Hi all,For you few who are sporadic computer users but want to come back to things as you left them...and/or you care deeply about the environment and want to stop your overnight drain...So you've gone to the trouble of re-enabling hibernate, and found that it's still...
  3. Fixed: Hibernate does not work

    in Windows 10 Software and Apps
    Fixed: Hibernate does not work: Hi all,For you few who are sporadic computer users but want to come back to things as you left them...and/or you care deeply about the environment and want to stop your overnight drain...So you've gone to the trouble of re-enabling hibernate, and found that it's still...
  4. Do anyone know how to fix and upgrade the SQL Server? Trying to upgrade 2014 SQL server....

    in Windows 10 Gaming
    Do anyone know how to fix and upgrade the SQL Server? Trying to upgrade 2014 SQL server....: Trying to upgrade 2014 SQL server. Once I open the SQL Server installation Center and click on " Upgrade from a previous version of SQL Server". Then it pops up the Browse for folder box, where I go to select the file location and then it keeps popping up this error message...
  5. Do anyone know how to fix and upgrade the SQL Server? Trying to upgrade 2014 SQL server....

    in Windows 10 Software and Apps
    Do anyone know how to fix and upgrade the SQL Server? Trying to upgrade 2014 SQL server....: Trying to upgrade 2014 SQL server. Once I open the SQL Server installation Center and click on " Upgrade from a previous version of SQL Server". Then it pops up the Browse for folder box, where I go to select the file location and then it keeps popping up this error message...
  6. Insert key not working

    in Windows 10 Customization
    Insert key not working: When I press the Insert key on my laptop in apps that make use of the Insert key, nothing happens. For instance in Freeplane, pressing the Insert key is supposed to create a child node on a mind map, but it doesn't work. I have also tried to use the Insert key in Freemind and...
  7. Insert key not working

    in Windows 10 Support
    Insert key not working: Yesterday, for the first time since I bought my laptop, I needed to use the Insert key (it says "Einfg" instead of "Ins" because I bought it from Germany). I tried it in two applications Freemind and Freeplane, in both of which it is supposed to create a child node on a mind...
  8. Insert error message in Access does not work?

    in Windows 10 Drivers and Hardware
    Insert error message in Access does not work?: In online lessons we should introduce an error message in Access but it doesn't work for me the way it worked for him When I entered the error message in the "Validity message" field, I received the following error messages The rules for data integrity have been...
  9. Why does INSERT not work here ????

    in Windows 10 Network and Sharing
    Why does INSERT not work here ????: When I try to insert some text copied from another place ... it won't insert here ! Why ? https://answers.microsoft.com/en-us/windows/forum/all/why-does-insert-not-work-here/eca81313-9225-4298-bc56-679f3f5434ff
  10. HIbernate does not work (and lots of the obvious fixes already tried

    in Windows 10 Support
    HIbernate does not work (and lots of the obvious fixes already tried: Exact description: Hibernate enabled (powercfg -h on) hiberfil.sys file present ( and = RAM) and tons of free space on C:\ When I click hibernate from power menu I see the following (a) Instant black screen but power light still on) (b) No change until I press and hold...