' Declare connection string variable Dim csSqlServer ' Declare command text variable Dim ctPhoto ' Declare recordset variable Dim rsPhoto ' Declare stream variable Dim stPhoto ' Declare argument constants Const adUseClient = 3 Const adOpenStatic = 3 Const adTypeBinary = 1 Const adStateOpen = 1 ' Define connection string csSqlServer = "Provider='sqloledb';Data Source='ws04';" &_ "Integrated Security='SSPI';Initial Catalog='AdventureWorks';" ' Define command text ctPhoto = "SELECT ProductPhotoID, LargePhoto " &_ "FROM Production.ProductPhoto " &_ "WHERE ProductPhotoID = 79" ' Create recordset object Set rsPhoto = CreateObject("ADODB.Recordset") ' set cursor location rsPhoto.CursorLocation = adUseClient ' Open recordset rsPhoto.Open ctPhoto, csSqlServer, adOpenStatic ' Define Stream object Set stPhoto = CreateObject("ADODB.Stream") stPhoto.Type = adTypeBinary stPhoto.Open stPhoto.Write rsPhoto.Fields("LargePhoto").Value stPhoto.SaveToFile "C:\Info\SqlServerPhoto.gif" ' Clean up If rsPhoto.State = adStateOpen Then rsPhoto.Close End If If stPhoto.State = adStateOpen Then stPhoto.Close End If Set csSqlServer = Nothing Set ctPhotol = Nothing Set rsPhoto = Nothing Set stPhoto = Nothing