Link to home
Start Free TrialLog in
Avatar of Cyber-Drugs
Cyber-DrugsFlag for United Kingdom of Great Britain and Northern Ireland

asked on

textcopy is not recognised as an internal or external command

Hi guys,

I am trying to create a batch routine to export some binary data from a table to files, but am having some problems.

Here is the code I've used:

CREATE PROCEDURE sp_textcopy (
  @srvname     varchar (30),
  @login       varchar (30),
  @password    varchar (30),
  @dbname      varchar (30),
  @tbname      varchar (30),
  @colname     varchar (30),
  @filename    varchar (30),
  @whereclause varchar (40),
  @direction   char(1))
AS
DECLARE @exec_str varchar (255)
SELECT @exec_str =
         'textcopy /S ' + @srvname +
         ' /U ' + @login +
         ' /P ' + @password +
         ' /D ' + @dbname +
         ' /T ' + @tbname +
         ' /C ' + @colname +
         ' /W "' + @whereclause +
         '" /F ' + @filename +
         ' /' + @direction
EXEC master..xp_cmdshell @exec_str


DECLARE @File nvarchar(50)
DECLARE @FileX nvarchar(50)
DECLARE @FileY nvarchar(50)
DECLARE Cur Cursor FOR
SELECT Name FROM dbo.Attachments
OPEN Cur
FETCH NEXT FROM Cur INTO @File

WHILE @@FETCH_STATUS=0
BEGIN
      SELECT @FileX = 'c:\' + @File
      SELECT @FileY = ' WHERE NAME=`' + @File + '`'
      EXEC sp_textcopy @srvname = 'localhost',
            @login = '*********',
            @password = '*************',
            @dbname = 'BAA',
            @tbname = 'dbo.Attachments',
            @colname = 'Attachment',
            @filename = @FileX,
            @whereclause = @FileY,
            @direction = 'O'
      FETCH NEXT FROM Cur INTO @File
END


It runs fine, but I get this error:


'textcopy' is not recognized as an internal or external command,
operable program or batch file.
NULL



Any ideas what I am doing wrong?

Thanks!
Avatar of Aneesh
Aneesh
Flag of Canada image

1.  you need to mention the path of the file
2.  or Copy that file into C:\
3.  Add a path command in Autoexec.Bat , which refers to the folder on which TextCopy.exe
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or simply copy that file to C:\
and use like
C:\textCopy /S
Avatar of Cyber-Drugs

ASKER

OK, that runs now, but now it's giving me an error about my WHERE clause...

TEXTCOPY Version 1.0
DB-Library version 8.00.194
SQL Server 'RAPIER-SERVER' Message 170: Line 1: Incorrect syntax near '`'. (Concerning line 1)
DB-Library Error 10007: General SQL Server error: Check messages from the SQL Server.
ERROR: Query execution failed.
NULL



I am using:

SELECT @FileY = ' WHERE NAME=`' + @File + '`'

because this didn't work:

SELECT @FileY = " WHERE NAME='" + @File + "'"


What can I use that will work?
replace that special character with '

SELECT @FileY = ' WHERE NAME='' + @File + '''
Ah, I was under the impression that wouldn't work, as it's the same quotes, but it works beautifully.

Thanks again aneeshattingal !! :)
Actually it was because you copied from the webpage ...