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
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. Update KB4345421, does this fix the Dolby Sound and other issues with feature update 1803?

    in Windows 10 Installation and Upgrade
    Update KB4345421, does this fix the Dolby Sound and other issues with feature update 1803?: I just noticed this update last night. I set my WiFi to Metered Connection as to not automatically download updates. I would like to know if this cumulative update fixes the issue some of us are having with the 1803 build, namely Dolby Audio being broken, and the system...
  3. How to fix File system error (-21472119196) on Windows 10?

    in Windows 10 BSOD Crashes and Debugging
    How to fix File system error (-21472119196) on Windows 10?: Some of my picture files on Windows 10 will not open due to File system error (-21472119196). Need help to fix this error. Thanks....
  4. How long is it going to take to fix Gears of War 4

    in Windows 10 Gaming
    How long is it going to take to fix Gears of War 4: Once again the game does not work. After purchasing for nearly 100 dollars this game has yet to work properly. There is constant tearing and artifacts during networked gameplay. What is the problem? Game keeps crashing on startup. This is a known issue. Quit telling to...
  5. how to fix file system error (-2147219196)

    in Windows 10 Support
    how to fix file system error (-2147219196): This error and Chrome browser "hiding itself upon opening" started soon after I installed 32 bit JAVA in order to make Open Office Grammar Checker extension function. I tried the easy fix methods where you simply click enable or disable some easy to access setting... no joy....
  6. Chrome not showing as an option for default browser (Fixed)

    in Windows 10 Customization
    Chrome not showing as an option for default browser (Fixed): I've been seeing a lot of issues regarding Google Chrome not showing in Windows Setting to set as a default browser. Fortunately, I've found a solution. 1. First go to Default Apps in Windows Setting. 2. Scroll down to find Set defaults by app as the last option and click...
  7. I am not able to fix this weird bug.

    in Windows 10 Customization
    I am not able to fix this weird bug.: [ATTACH] There is no space between the Icons and the text. They are overlapping. https://answers.microsoft.com/en-us/windows/forum/windows_10-start-win_menu/i-am-not-able-to-fix-this-weird-bug/75f90c28-312e-4c84-9ca8-9e9a4928dad1
  8. I'm the administrator. How to fix this?

    in Windows 10 Support
    I'm the administrator. How to fix this?: I'm working on an issue with my PC & need to open the Device Manage to check hardware. I keep getting this "An administrator has blocked you from running this app" error. Huh? I'm the administrator. How to fix this? 114516
  9. A lot of programs fail to work, and windows refuses to fix itself or reset!

    in Windows 10 BSOD Crashes and Debugging
    A lot of programs fail to work, and windows refuses to fix itself or reset!: Hello, so a few weeks ago I boot up my pc to find that a lot of programs did not load in, and showed errors like EXAMPLE.EXE - BAD IMAGE "Example.dll is not designed to run with windows or contains an error" or either CLR Error 80004005 this program will now terminate. So I...
  10. dism fails to fix corruption with 0x800f081f error

    in Windows 10 BSOD Crashes and Debugging
    dism fails to fix corruption with 0x800f081f error: Background: HP ENVY Desktop 750-514 running Windows 10 build 17134.112 System has experienced some problems in the past but I was able to fix them with DISM. Current Problem: Windows update KB4338819 runs and results in a stopcode of 0xc000021a. Automatic Repair does not...