Solved

SQL Server 2008 Image to File (textcopy.exe)

Posted on 2009-06-30
14
4,601 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
  • 6
  • 5
  • 3
14 Comments
 
LVL 42

Expert Comment

by:EugeneZ
Comment Utility
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 42

Expert Comment

by:EugeneZ
Comment Utility
0
 
LVL 42

Accepted Solution

by:
EugeneZ earned 250 total points
Comment Utility
0
 
LVL 18

Author Comment

by:Data-Man
Comment Utility
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 42

Expert Comment

by:EugeneZ
Comment Utility
ok , you did not tell you need them out of DB
Did you try SSIS (like DTS)?
0
 
LVL 42

Expert Comment

by:EugeneZ
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 42

Expert Comment

by:EugeneZ
Comment Utility
check my last posted links
0
 
LVL 18

Author Comment

by:Data-Man
Comment Utility
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
Comment Utility
>>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
Comment Utility
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
Comment Utility
>>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
Comment Utility
>>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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now