I am using following code to retrieve a file from database from a BLOB column. I am able to retrieve the file and save in c:\temp directory, but VBA adds some junk characters at start of file making some files like jpg images un-readable. Can anyone tell whats wrong with the code or or do I need to use some other driver for connection etc...
Code:
Sub Test()
Dim ProdConnectString
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim myStreaM As New ADODB.Stream
'String used for connecting to DB
ProdConnectString = "provider=msdaora.1;user id=user;password=psd;data source = ds;option=1+2+8+32+2048+16384"
Set conn = New ADODB.Connection
conn.ConnectionString = ProdConnectString
conn.CursorLocation = adUseClient
conn.Open
rs.Open "select file_data from TABLE where NAME ='ABCD.txt'", conn
myStreaM.Open
myStreaM.WriteText rs!file_data
myStreaM.SaveToFile "c:\temp\XYZ.txt" , adSaveCreateOverWrite
myStreaM.Close
rs.Close
conn.Close
End Sub
File example (first 2 characters are junk, same characters are repeated in all files):
ÿþ1
2
3
4
5
6
7
8
9
10
Thanks.
~BS