BCP query out executed by xp_cmdshell works fine from query analyzer but fails from VB Component

Ask a Question related to Microsoft SQL / MS SQL Server, Design and Development.

  1. #1

    Default BCP query out executed by xp_cmdshell works fine from query analyzer but fails from VB Component

    Hi all,

    I have a stored procedure which returns a vast number of record and i
    have to write the output into a csv file. I'm using BCP utility to do
    this and BCP utility is executed by xp_cmdshell from inside another
    stored procedure.

    Everything works fine from developement server but when the code was
    deployed at client end on live server the code is not being executed
    from component though on live server from SQL query analyzer it works
    fine but from component it fails.

    What could be the reason behind

    My code is

    CREATE PROCEDURE ParishPay_GenerateSouthDataCSV
    (
    @return_value int output,
    @School_id int,
    @session varchar(50),
    @filename varchar(100)
    )
    AS

    DECLARE @bcpCommand varchar(2000)
    DECLARE @Arguments varchar(50)
    DECLARE @result int

    SET @Arguments = @School_id
    SET @Arguments = @Arguments + ','''
    SET @Arguments = @Arguments + @session + ''

    SET @bcpCommand = '" bcp "exec DTMSv3MG.dbo.SouthDataPaymentCouponCSV
    '
    SET @bcpCommand = @bcpCommand + @Arguments + ''' " queryout "'
    SET @bcpCommand = @bcpCommand + @FileName + '" -U Username -P password
    -S Server -c -T -t "," "'


    select @bcpCommand

    EXECUTE @return_value = master..xp_cmdshell @bcpCommand

    SELECT @return_value as return_value

    GO

    I don't think there is any problem in the code as it works fine on
    developement server. Even no error is logged it the sp fails then
    error should be logged but what i doubt either BCP fails orelse
    xp_cmdshell is not being executed in live server from component.

    Please suggest me a solution. Is it a problem with permission??

    Thanks
    anamika Guest

  2. Similar Questions and Discussions

    1. CFSTOREDPROC to Oracle on Linux fails - same query onWin2003 works
      Hi folks I hope you can help me. I'm having a terrible time trying to get a query to work. I've got a CF MX6.1 Standard system talking to an...
    2. Query works in fine CF5 but not CFMX
      I have a simple query against an Oracle database that works in CF 5 but not in CFMX. In CF 5 I get one record which is what I want, but in CFMX I...
    3. 'Text' data type returned differently between ASP & Query Analyzer
      I have the SQL 2000 server with a database table having one 'text' data type column. This column stores the general text message (normally body of...
    4. sql statement works in query analyzer but not in asp/ado?
      I am new to asp/ado (well and sql server)... this has been driving me mad for hours now. I have created an SQL statment using access query design. I...
    5. Generate Table script from query analyzer...
      You can use SQL-DMO to do that but not straight tsql. -- Andrew J. Kelly SQL Server MVP "Robert Taylor" <robertt@rtnetworks.com> wrote...
  3. #2

    Default Re: BCP query out executed by xp_cmdshell works fine from query analyzer but fails from VB Component

    Try to catch the error message. Most likely it's security related. Does the
    user have rights to run xp_CMDShell?

    Gary


    "anamika" <anamikas@mindfiresolutions.com> wrote in message
    news:d9c65892.0307012216.4e6e902f@posting.google.c om...
    > Hi all,
    >
    > I have a stored procedure which returns a vast number of record and i
    > have to write the output into a csv file. I'm using BCP utility to do
    > this and BCP utility is executed by xp_cmdshell from inside another
    > stored procedure.
    >
    > Everything works fine from developement server but when the code was
    > deployed at client end on live server the code is not being executed
    > from component though on live server from SQL query analyzer it works
    > fine but from component it fails.
    >
    > What could be the reason behind
    >
    > My code is
    >
    > CREATE PROCEDURE ParishPay_GenerateSouthDataCSV
    > (
    > @return_value int output,
    > @School_id int,
    > @session varchar(50),
    > @filename varchar(100)
    > )
    > AS
    >
    > DECLARE @bcpCommand varchar(2000)
    > DECLARE @Arguments varchar(50)
    > DECLARE @result int
    >
    > SET @Arguments = @School_id
    > SET @Arguments = @Arguments + ','''
    > SET @Arguments = @Arguments + @session + ''
    >
    > SET @bcpCommand = '" bcp "exec DTMSv3MG.dbo.SouthDataPaymentCouponCSV
    > '
    > SET @bcpCommand = @bcpCommand + @Arguments + ''' " queryout "'
    > SET @bcpCommand = @bcpCommand + @FileName + '" -U Username -P password
    > -S Server -c -T -t "," "'
    >
    >
    > select @bcpCommand
    >
    > EXECUTE @return_value = master..xp_cmdshell @bcpCommand
    >
    > SELECT @return_value as return_value
    >
    > GO
    >
    > I don't think there is any problem in the code as it works fine on
    > developement server. Even no error is logged it the sp fails then
    > error should be logged but what i doubt either BCP fails orelse
    > xp_cmdshell is not being executed in live server from component.
    >
    > Please suggest me a solution. Is it a problem with permission??
    >
    > Thanks

    Gary X Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139