using System;using System.Web;using System.Web.Services;using System.Data.SqlClient;using System.Data; using connectionclass; public course Handler : IHttpHandler public void ProcessRequest(HttpContext context) link con = brand-new connection(); con.getconnectionstring(); cable imageid = context.Request.QueryString<"ImID">; SqlCommand command = brand-new SqlCommand("select photos from Upload_images wherein Image_ID=" + imageid, connection.con); SqlDataReader dr = command.ExecuteReader(); dr.Read(); context.Response.BinaryWrite((Byte<>)dr<0>); context.Response.End(); dr.Close(); connection.con.Close(); windy bool IsReusable gain return false;


SqlConnection link = brand-new SqlConnection("connection string");SqlCommand cmd = new SqlCommand("SELECT * from SomeTable", connection);SqlDataReader reader = cmd.ExecuteReader();connection.Open();if (reader != null) while (reader.Read()) //do miscellaneous reader.Close(); // reader.Dispose(); // connection.Close(); // Instead, wrap them in making use of statements:
using(SqlConnection link = new SqlConnection("connection string")) connection.Open(); using(SqlCommand cmd = brand-new SqlCommand("SELECT * indigenous SomeTable", connection)) utilizing (SqlDataReader leader = cmd.ExecuteReader()) if (reader != null) when (reader.Read()) //do other // leader closed and disposed up here // command disposed here //connection closed and also disposed hereThe using statement will certainly ensure correct disposal the the object and freeing of resources.If friend forget then you space leaving the cleaning approximately the garbage collector, which could take a while
perhaps the following attach could assist you<^>
nearby the DataReader & climate SqlConnection, if there is an exception is not acquiring closed.

You are watching: There is already an open datareader associated with this command which must be closed first.

best methods to compose this code in try catch ultimately ultimately block near the objects.Something like this.

SqlConnection conn = null;SqlCommand cmd = null;try conn = new SqlConnection(Settings.Default.qlsdat_extensionsConnectionString) cmd = new SqlCommand(reportDataSource, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("
endDate", SqlDbType.DateTime).Value = end; conn.Open(); //opens connection DataSet dset = new DataSet(); new SqlDataAdapter(cmd).Fill(dset); this.gridDataSource.DataSource = dset.Tables<0>;catch(Exception ex) Logger.Log(ex); throw;finally if(conn != null) conn.Dispose(); if(cmd != null) cmd.Dispose();
I have actually read and also agree come the terms of Service and Privacy plan Please i ordered it me to the newsletters
as soon as answering a question please: read the inquiry carefully.Understand the English isn"t everyone"s very first language so it is in lenient that badspelling and also grammar.If a concern is poorly phrased then either ask because that clarification, overlook it, oredit the question
and fix the problem. Insults space not welcome. Don"t tell someone to read the manual. Possibilities are they have and also don"t get it. Carry out an prize or move on come the following question. Let"s work-related to help developers, no make them feel stupid.

See more: Flights From Sfo To Mco Nonstop, Direct (Non

This content, in addition to any associated source code and also files, is licensed under The code Project open License (CPOL)

System.invalidoperationexception: "there is already an open datareader connected with this command which should be closeup of the door first."
InvalidOperationException: over there is currently an open DataReader associated with this Command which have to be closed first.