Load Text file

  • I have a SP which loads a text file into sql server tables. This SP is used in the application where the end user has to browse for the file and load it into tables. Now I want to raise some errors on the given conditions in my SP

    How can I send the error message to the user who loads the file when he is trying to load it

  • From BOL v9:

    RAISERROR ( { msg_id | { msg_str | @local_variable} }{ ,severity ,state }    [ ,argument [ ,...n ] ] )    [ WITH option [ ,...n ] ]

    msg_id

    Is a user-defined error message number stored in the sys.messages catalog view using sp_addmessage. Error numbers for user-defined error messages should be greater than 50000. When msg_id is not specified, RAISERROR raises an error message with an error number of 50000.

    msg_str

    Is a user-defined message with formatting similar to the printf function in the C standard library. When msg_str is specified, RAISERROR raises an error message with an error number of 5000.
    msg_str is a string of characters with optional embedded conversion specifications. Each conversion specification defines how a value in the argument list is formatted and placed into a field at the location of the conversion specification in msg_str...

    severity

    Is the user-defined severity level associated with this message. When using msg_id to raise a user-defined message created using sp_addmessage, the severity specified on RAISERROR overrides the severity specified in sp_addmessage.
    Severity levels from 0 through 18 can be specified by any user. Severity levels from 19 through 25 can only be specified by members of the sysadmin fixed server role or users with ALTER TRACE permissions. For severity levels from 19 through 25, the WITH LOG option is required.
    Severity levels less than 0 are interpreted as 0. Severity levels greater than 25 are interpreted as 25.

    state

    Is an arbitrary integer from 1 through 127. A negative value for state defaults to 1. The value 0 or values larger than 127 generate an error.

    argument

    Are the parameters used in the substitution for variables defined in msg_str or the message corresponding to msg_id. There can be 0 or more substitution parameters, but the total number of substitution parameters cannot exceed 20. Each substitution parameter can be a local variable or any of these data types: tinyint, smallint, int, char, varchar, nchar, nvarchar, binary, or varbinary. No other data types are supported.

    option

    Is a custom option for the error and can be one of these values:

    LOG

    Logs the error in the error log and the application log for the instance of the Microsoft SQL Server Database Engine. Errors logged in the error log are currently limited to a maximum of 440 bytes. Only a member of the sysadmin fixed server role or a user with ALTER TRACE permissions can specify WITH LOG.

    NOWAIT

    Sends messages immediately to the client.

    SETERROR

    Sets the @@ERROR and ERROR_NUMBER values to msg_id or 50000, regardless of the severity level.

    Tim Wilkinson

    "If it doesn't work in practice, you're using the wrong theory"
    - Immanuel Kant

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply