Tuesday, February 21, 2012

returning my blob next problem

Dear All,

I am trying to run the some code which is designed to return an image blob. However it throws an exception

Exception Details:System.IndexOutOfRangeException: ToolbarLogo

Source Error:

Line 55: Response.ClearHeaders() ;
Line 56: Response.ContentType = "image/gif";
Line 57: byte[] arr = (byte[]) sdr["ToolbarLogo"];
Line 58:
Line 59: Response.BinaryWrite(arr);

I can run the sql SP query fine and it returns binary data ok:

Does anyone have any pointers I should look at as to why the error is thrown? Do you think my blobs are corrupt?

Here is the code:

Thank you for takin the time to look


public class GetBanner : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Image Image1;

protected void Page_Load(object sender, EventArgs e)
{
SqlDataReader sdr = null;

int brand_id = 0;
try
{
brand_id = Int32.Parse(Request.QueryString["brand_id"].ToString());
}
catch (Exception)
{
// commented below. Since it is a image handleer
//Response.Write("<HTML>You must supply a brand_id</HTML>");
return;
}

{
SqlDataAdapter daGetBanner = new SqlDataAdapter();


string connectionInfo = ConfigurationSettings.AppSettings["ConnectionInfo"];
using(SqlConnection dbConnection = new SqlConnection(connectionInfo))

{
SqlCommand objCommand = new SqlCommand("usp_get_new_guid_r", dbConnection);
objCommand.CommandType = CommandType.StoredProcedure;

dbConnection.Open();
sdr = objCommand.ExecuteReader();
while (sdr.Read())
{
Response.ClearHeaders() ;
Response.ContentType = "image/gif";
byte[] arr = (byte[]) sdr["ToolbarLogo"];

Response.BinaryWrite(arr);
Response.Flush();
}
sdr.Close();

dbConnection.Close();
}
}
}

if(sdr["ToolbarLogo"] != null ||sdr["ToolbarLogo"] != DBNull.Value )

{

byte[] arr = (byte[]) sdr["ToolbarLogo"];

Response.BinaryWrite(arr);

Response.Flush();

}

No comments:

Post a Comment