你调用的对象是空的

你调用的对象是空的

本文介绍了你调用的对象是空的.请解决这个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

public class ImageHandler : IHttpHandler {
    string strcon = ConfigurationManager.AppSettings["ConnectionString"].ToString();

    public void ProcessRequest (HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        context.Response.Write("Hello World");
        string imageid = context.Request.QueryString["ImID"];
        SqlConnection connection = new SqlConnection("Data Source=CIODEV03\\SQLEXPRESS;Initial Catalog=EmployeeDB;Integrated Security=True");
        connection.Open();
        SqlCommand command = new SqlCommand("select Image from Image1 where ImageId=" + imageid, connection);
        SqlDataReader dr = command.ExecuteReader();
        dr.Read();
        context.Response.BinaryWrite((Byte[])dr[0]);
        connection.Close();
        context.Response.End();
    }

    public bool IsReusable {
        get {
            return false;
        }
    }
}





错误..........

对象引用未设置为对象的实例.
说明:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息.

异常详细信息:System.NullReferenceException:对象引用未设置为对象的实例.

源错误:





error..........

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 7:
Line 8:  public class ImageHandler : IHttpHandler {
Line 9:      string strcon = ConfigurationManager.AppSettings["ConnectionString"].ToString();
Line 10:
Line 11:     public void ProcessRequest (HttpContext context)

推荐答案

ConfigurationManager.AppSettings["ConnectionString"].ToString();



为空,因为您可能尚未在webconfig文件中对其进行初始化.

因此,尝试检查那里是否可以找到解决方案.

如果可以帮助您,则将其标记为您的答案,我可以查询.

谢谢



is blank as you may not have initialized it in the webconfig file.

So try to check there you may get the solution there.

If it helps you out then mark this as your answer and i am open to queries.

Thanks


这篇关于你调用的对象是空的.请解决这个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:53