views:

433

answers:

2

Similar to this question only the other way of flow.

http://stackoverflow.com/questions/416881/insert-picture-into-sql-server-2005-image-field-using-only-sql

I need to be able to save a image field out into the file system and be able to name the file with only using SQL. I don't want to use TEXTCOPY either because I need to use the connection to the database that is running the query itself.

I'd like this to work in SQL 2005 to support older database clients but if it's available in only 2008 that's fine.

Any ideas?

A: 

I don't believe there is a way to save out using only sql, but there is a command-line utility, bcp.

Totty
Yes, bcp is near the same to TEXTCOPY. An external executable that connects to the database via login info that needs to be provided. The reason I do not want to do this is I do not want to store login information inside the text of a stored procedure.
GluedHands
+1  A: 

With SQL 2k8 there is the new FILESTREAM type that covers such cases. Filestreams can be opened via the Win32 file access handle like any other file, but hey are integrated into the database from transaction and backup/restore point of view.

I had a similar issue in SQL 2k5 and my solution was to use a CLR stored procedure with EXTERNAL_ACCESS that was writing into the file system using C# file operations.

Remus Rusanu