我做的asp.net在开发的机器上正常,部署到另外一台机器上出现“未将对象引用设置到对象的实例”。具体是在登陆页面,输入用户名,密码,提交之后出现的,是什么问题呢?在出问题的机器上(win xp)只装了IIS5,.net framework 1.1;数据库是mysql 5.0。
已经设置了虚拟目录,并且设置成了应用程序。

解决方案 »

  1.   

    >>>“未将对象引用设置到对象的实例”先看一下哪个对象是null,是不是数据库传回的数据问题?
      

  2.   

    请问怎么检查哪个是null,我是超级菜的那种。
      

  3.   

    如果用debug版本的话,“未将对象引用设置到对象的实例”应该指明哪行编码有问题,再看一下那几行编码的数据,譬如如果你有个变量叫A,那么看一下Response.Write(A==null);
      

  4.   

    没有使用第三方控件,看看错误信息:
    ===================================Server Error in '/cmesm/admin' Application.
    --------------------------------------------------------------------------------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: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  Stack Trace: 
    [NullReferenceException: Object reference not set to an instance of an object.]
       admin.login.submit_ServerClick(Object sender, EventArgs e) in D:\Xu Yunzhe\My Design\CMESM\admin\login.aspx.cs:97
       System.Web.UI.HtmlControls.HtmlInputButton.OnServerClick(EventArgs e) +108
       System.Web.UI.HtmlControls.HtmlInputButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
       System.Web.UI.Page.ProcessRequestMain() +1277 
    --------------------------------------------------------------------------------
    Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
      

  5.   

    这个是原码:
    =============================================using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Configuration;
    using System.Data;
    using System.Data.Odbc;
    using System.Drawing;
    using System.Web;
    using System.Web.Security;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace admin
    {
    /// <summary>
    /// Summary description for login.
    /// </summary>
    public class login : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.TextBox id;
    protected System.Web.UI.WebControls.TextBox pwd;
    protected System.Web.UI.HtmlControls.HtmlInputButton submit;
    protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
    protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
    protected System.Web.UI.WebControls.CheckBox PersistCookie;
    protected System.Web.UI.WebControls.Label Message;
    protected System.Web.UI.HtmlControls.HtmlForm FormAuthentication;
    protected OdbcDataReader myReader;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here
    } #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {    
    this.submit.ServerClick += new System.EventHandler(this.submit_ServerClick);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void submit_ServerClick(object sender, System.EventArgs e)
    {

    string post = id.Text;
    string ConnectionString = ConfigurationSettings.AppSettings["MySqlConnectionString"];
    string CommandText = "select * from administrator where administrator='" + post + "'";

    OdbcConnection myConnection = new OdbcConnection(ConnectionString);
    OdbcCommand myCommand = new OdbcCommand(CommandText, myConnection);

    try
    {
    // open connection to the database
    myConnection.Open();
        
    // run query
    myReader = myCommand.ExecuteReader();
        
    if (myReader.Read())
    {
    if ((id.Text == (string)myReader.GetValue(1)) && (pwd.Text == (string)myReader.GetValue(2)))
    {
    FormsAuthentication.RedirectFromLoginPage(id.Text, PersistCookie.Checked);
    }
    else
    {
    Message.Text = "Illegal username or password, please try again!";
    }
    }    
    }
    catch (Exception ex)
    {
    // If an exception occurs, handle it.
    throw (ex);
    }
    finally
    {
    // Whether we succeed or fail, close the database connection
    myReader.Close();
    myConnection.Close();
    }
    }
    }
    }
      

  6.   

    问题已经解决,原因是连接数据库的用户“web_user”没给赋予select,insert,update,delete的权限,晕死了。谢谢大家帮助!!!