Solved

SQL Server 2008 Image to File (textcopy.exe)

Posted on 2009-06-30
14
4,764 Views
Last Modified: 2013-05-24
Hi everyone,
    I currently have a SQL Server 2000 database and we are storing small graphics in the database.  No problem getting them in, we use an ADO stream.  Very fast!!  No worries there.  We use TextCopy.exe to move the images to a file and then email.  No worries there either.

    Now I'm working on a SQL Server 2008 database and I can stream the images to the database all day long, but I can't find the TextCopy command anywhere in the install.  Did they remove it from 2008?  Is there a better way to take am graphic from an image field and put it to file?
    I've been searching the web and EE and seem to be hitting a dead end.  Can someone please point me in the right direction?

Thanks,
Mike
0
Comment
Question by:Data-Man
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 3
14 Comments
 
LVL 43

Expert Comment

by:Eugene Z
ID: 24747424
TextCopy.exe is gone in sql 2005-2008
-----
however you can try to use textcopy.exe in SQL 2008:
copy it to sql server 2008 from 2000 and try to run it e.g. from xp_cmdshell
 --
also
try solution from
http://www.eggheadcafe.com/forumarchives/SQLServerserver/Jan2006/post26065778.asp 
SELECT BlobData.*  
 
FROM OPENROWSET  
 
(BULK ''' + @FileName + ''',  
 
SINGLE_BLOB)
--
 
more
http://msdn.microsoft.com/en-us/library/ms190312.aspx 
0
 
LVL 43

Expert Comment

by:Eugene Z
ID: 24747442
0
 
LVL 43

Accepted Solution

by:
Eugene Z earned 250 total points
ID: 24747464
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 18

Author Comment

by:Data-Man
ID: 24747627
Eugene,
     I appreciate all the links, but I've seen them before.  Here is what I used to have in 2000.

SELECT @strExec = 'C:\Progra~1\Micros~1\MSSQL\Binn\textcopy.exe /S /U ' + SYSTEM_USER
SELECT @strExec = @strExec + ' /P ' + @strPW + ' /D Balance_StRegis_NYC /T tblApplicationComments /C ScreenImage '
SELECT @strExec = @strExec + '/W "WHERE ApplicationCommentID=' + @strID + '" /F ' + @strLocalFileName + ' /O'
                        
EXEC master..xp_cmdshell @strExec

This little snippet of code would take one image from a single record and write it to a file.  All the links you are showing me take me down a different path.  I do not program in any version of C.

I have to believe that there is a simple way via T-SQL to take the data in an image field and put it to a file in SQL Server 2008.

I can't be the only person in the world trying to do this.

Thanks,
Mike
0
 
LVL 43

Expert Comment

by:Eugene Z
ID: 24747838
ok , you did not tell you need them out of DB
Did you try SSIS (like DTS)?
0
 
LVL 43

Expert Comment

by:Eugene Z
ID: 24748288
please check
HOW TO: Read and Write a File to and from a BLOB Column by Using Chunking in ADO.NET and Visual Basic .NET
http://support.microsoft.com/kb/317034
---
Save and Display Images using ASP .NET 2.0 Profile
http://www.dotnet-friends.com/articles/asp/artinasp03e650de-2b15-4fb1-9bdb-aad1a1e5ac5c.aspx 
 
0
 
LVL 18

Author Comment

by:Data-Man
ID: 24748420
Please reread my original post.

It says that I don't have any problems putting the graphics in the SQL Server database.

The question I asked was.....Is there a better way to take a graphic from an image field and put it to file?

I do not want to stream the image back to the client and do something with it there.  I need to put the image to a local file on the server (which is why I was using TextCopy).  Once it's local then I can use dbmail to send an email with the graphic as an attachment.

Hope this helps

Thanks,
Mike
0
 
LVL 43

Expert Comment

by:Eugene Z
ID: 24749369
check my last posted links
0
 
LVL 18

Author Comment

by:Data-Man
ID: 24749537
I am looking for a solution that runs on the SQL Server Box...preferrably a T-SQL Solution.

Mike



0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24759668
>>preferrably a T-SQL Solution<<
You are out of luck.  There is no T-SQL only solution (and never has been)
0
 
LVL 18

Author Comment

by:Data-Man
ID: 24759748
acperkins,
It's been a couple of years, but I think you've answered a question or two of mine in the past and I'm sure I've used a solution or two that you have posted.  :-)

TextCopy worked great.  Used it for years.  The command was executed in a command shell, but was still accomplished by executing a proc.

There isn't a workaround in 2008 for the removal of the textcopy command?

Is there another solution to populating the attachment with a graphic contained within the image data type without sending it down to the client?

I have to believe that there has to be a way to take the data in an image field and write it to a file (at the server).


Thanks,
Mike
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24762712
>>TextCopy worked great. <<
I know exactly what is TextCopy, it is a utility built for exactly the purpose you need and I have actually used it about 10 years ago.  But it is not T-SQL.  

>>The command was executed in a command shell, but was still accomplished by executing a proc. <<
So does Notepad.  That does not qualify it as T-SQL.

>>There isn't a workaround in 2008 for the removal of the textcopy command?<<
Did you not see the comment http:a24747424 ?

>>Is there another solution to populating the attachment with a graphic contained within the image data type without sending it down to the client?<<
Not without writing an app to do it and install on the server.

>>I have to believe that there has to be a way to take the data in an image field and write it to a file (at the server).<<
See above.

>>I can't be the only person in the world trying to do this.<<
In general it is not considered good practice to store images in the database, that is why there has never been much demand for it.  Having said that, MS SQL Server has introduced a new attribute called FILESTREAM that makes the process somewhat more palatable.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24762744
>>It's been a couple of years, but I think you've answered a question or two of mine in the past and I'm sure I've used a solution or two that you have posted. <<
And if you look carefully you will actually find VB6 solutions using ADO that I have posted for reading and writing image data to the database.  I realize this is not what you need and instead are looking for an ellusive T-SQL solution, however I mention this so that you are aware that I know exactly what you are after.
0
 
LVL 18

Author Closing Comment

by:Data-Man
ID: 31599767
I was looking for a work around solution that could be run via a stored procedure.  After a day of searching, building and testing I was able to create a working solution.  The final solution use the stored procedure xp_cmdShell to execute an SSIS package, but it does not employ the TextCopy command.  And a xp_cmdShell is still available in SQL Server 2008 the solution is viable.

After clicking on the SSIS link to Microsoft and seeing the Export Column Transformation capabilities, it pointed me in the right direction. I scoured the web for examples and found one that really helped.

How to create an Export Column Transformation SSIS package
http://books.google.com/books?id=i4gg8AqZHMoC&pg=PA159&lpg=PA159&dq=create+%22export+column%22+ssis+package&source=bl&ots=B0hes5TRel&sig=4m2DOxfs4pgzojULZ2Y8ZEGBqqc&hl=en&ei=h2ZPSoXqJ4LwsQPNm_nWBQ&sa=X&oi=book_result&ct=result&resnum=10

The above link was probably the most helpful, but also required a lot of other research.  I have never created an SSIS package before so there were a number of steps that required multiple Google searches to determine how to accomplish said step.

How to execute an SSIS package with variables via T-SQL.
http://www.codeproject.com/KB/database/Call_SSIS_from_SP.aspx

Found out that variables within the SSIS are case sensitive.
http://sqlblogcasts.com/blogs/simons/archive/2007/07/23/SSIS---Variable-lists-for-the-script-task-are-case-sensitive.aspx

I normally dont worry whether or not my not my variables are case sensitive.  Since I follow strict naming conventions, my variables are always referenced the same as they are declared.  

And finally with a couple of hours of trouble shooting I found out that not only the variables must be case sensitive, but so is the word Value, it must start with an upper case V.  Which is interesting because it makes no difference if the word SET is upper or lower, it still works.

'/SET \package.variables[User::ID].value;"\"' + @strID + '\""

Is not the same as

'/SET \package.variables[User::ID].Value;"\"' + @strID + '\""

Notice the second one has an upper case V for value.  It will NOT work with a lower case v.

If you are looking for a workaround to the TextCopy command to move a file from your database to a local file, the above links should help you create a solution.

Happy coding!!

Mike
0

Featured Post

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question