I use Oracle to store photos. You need to retrieve the photo with a out parameter that is of the same type as the field the photo is stored in. I assume it's a BLOB. Before storing the photo in the database you have to convert it to a byte array. As that wasn't the question here, I'll post the code I use to retrieve the photo from my Oracle database, it should be a simple matter to convert to Sql Server code.
I open a connection to the database and pass that to the retrieve function. I return a dataset that has one row of data, the photo and other identifying information. I then assign the BLOB to a variable, from there do what you need. What I do with it is assign it to an image control which calls another aspx page to retrieve the photo (imageURL). The code to retrieve it is in the called "Image.aspx", which then returns the photo to the image control. The html for that is below the GetPhoto Function. This way I do not need to store the photo anywhere on the hard drive and retrieve it.
Dim MyConnection As New OracleConnection
Dim MyDataSet As New DataSet
Dim MyPhoto() As Byte = {}
MyConnection = OpenConnection(Session("USERNAME"), Session("PASSWORD"))
MyDataSet = GetPhoto(MyConnection, pPhotoID)
myPhoto = MyDataSet.Tables("Data").Rows(0)("Photo")
Public Function GetPhoto(ByVal TheConnection As OracleConnection, ByVal pPhotoID As String) As DataSet
Dim myCommand As New OracleCommand
Dim DS As New DataSet
Try
With myCommand
.Connection = TheConnection
.CommandText = "Darlington.PlayerSignUps.GetPhoto"
.CommandType = CommandType.StoredProcedure
.Parameters.Clear()
.Parameters.Add(New OracleParameter("pPhotoID", OracleDbType.Varchar2, pPlayerID.Length)).Value = pPhotoID
.Parameters.Add(New OracleParameter("pDataOut", OracleDbType.RefCursor))
.Parameters(0).Direction = ParameterDirection.Input
.Parameters(1).Direction = ParameterDirection.Output
Dim DA As New OracleDataAdapter(myCommand)
DA.Fill(DS, "DATA")
GetPhoto = DS
End With
Catch exc As Exception
Throw New Exception("Error occured while retreiving photo from database, the error is: " & exc.Message)
End Try
myCommand = Nothing
End Function
<tr>
<td style="width: 372px; text-align: center">
<asp:Image ID="Image_Photo" runat="server" ImageUrl="Image.aspx" />
</td>
</tr>