hey there, I'm writing a program where I have to store and retrive student information(e.g. name,address,photo..) in the database. I've written the code to interact with the database in a WCF service..The problem is I'm able to get the image from the database if I directly write the code to interact with the database in the Windows Forms Application..but when I try to get the image through the WCF service there's some sort of error saying "The underlying connection was closed: The connection was closed unexpectedly."
I don't understand where I'm going wrong..Could anyone please tell me why am I getting this error???
The function in the WCF service that retrieves the image is given below

public System.Drawing.Image GetImageByRecID(int iRecID)
        {
            System.Drawing.Image imgResult = null;
            try
            {
                OpenConnection();
                string sqlQuery = @"SELECT Stud_photo FROM Student_PhotoTable WHERE (STUD_ID=" + iRecID.ToString() + ")";
                sqlCmd.CommandText = sqlQuery;

                SqlDataReader dtreader = sqlCmd.ExecuteReader();                

                if (dtreader.HasRows)
                {
                    dtreader.Read();
                    byte[] imageBytes = (byte[])dtreader["Stud_photo"];

                    imgResult = this.ByteArrayToImage(imageBytes);
                }

                CloseConnection();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                CloseConnection();
            }
            return imgResult;
        }

...the OpenConnection() and CloseConnection() are functions to open and close the database connection respectively..and the byteArrayToImage() function just converts the byteArray into the corresponding image

I got it right..just return the byte array from the WCF service and then change the byte array into the image in the client application

This question has already been answered. Start a new discussion instead.