using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
public class Handler : IHttpHandler
{
const string Con_string = @"Data Source=DESKTOP10\SQLEXPRESS;Initial Catalog=Office;Integrated Security=True";
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/msword";
SqlConnection con = new SqlConnection(Con_string);
SqlCommand cmd = new SqlCommand("Select * from Resource where id=@id");
cmd.Parameters.AddWithValue("@id", context.Request["id"]);
using (con)
{
con.Open();
byte[] file = (byte[])cmd.ExecuteScalar();
context.Response.BinaryWrite(file);
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
I got below error. What should i do to solve this?

John SmithPosted Jul 27, 2011, 2:02 AM
i think u have to pass connection object 'con' along with your query to SqlCommand......
like this.....
SqlCommand cmd = new SqlCommand("Select * from Resource where id=@id",con);
Suthish NairPosted Jul 27, 2011, 1:56 AM
Why don't refer an msdn article