I need to pull some BLOB data from a SQL Server 2005 database and generate a SQL script to insert this same data in another database, in another server.
I am only allowed to do this using SQL scripts, I can’t use any other utility or write a program in Java or .NET to do it.
The other big restriction I have is that I don’t have access to the original database (where the original BLOB data is) when I run the script, to copy the BLOB data to the target database, so the data should already be encoded within the SQL script file.
Summing up: is there a way to encode the BLOB data into text so that I can dump it into a SQL INSERT command within a script text file and run it?
I am able to run special T-SQL statements and stored procedures if needed to.
TEXTCOPY was a sample application included in SQL Server 7.0 and 2000 but no longer available in SQL Server 2005.
However, googling for TEXTCOPY in SQL Server 2005, I found this alternative that might do the trick:
http://sequelserver.blogspot.com/2007/01/texcopy-sql-server-2005.html
It relies on writing and reading the binary data from the filesystem, which in my case is not ideal (ideally I would like to encode the binary data with the SQL script text file itself), but it’s the best I’ve found so far.
Here’s another good source on how to do binary import/export operations using BULK OPENROWSET: http://msdn.microsoft.com/en-us/library/ms191184.aspx