问题描述
报错信息如下:有关调用实时(JIT)调试而不是此对话框的详细信息,请参见此消息的结尾。**************异常文本**************System.NullReferenceException:未将对象引用设置到对象的实例。在GasManpowerMeasurePoint.MainForm.GetConfig()在GasManpowerMeasurePoint.MainForm.Data_refresh()在GasManpowerMeasurePoint.MainForm.MainForm_Load(Objectsender,EventArgse)在System.Windows.Forms.Form.OnLoad(EventArgse)在System.Windows.Forms.Form.OnCreateControl()在System.Windows.Forms.Control.CreateControl(BooleanfIgnoreVisible)在System.Windows.Forms.Control.CreateControl()在System.Windows.Forms.Control.WmShowWindow(Message&m)在System.Windows.Forms.Control.WndProc(Message&m)在System.Windows.Forms.ScrollableControl.WndProc(Message&m)在System.Windows.Forms.ContainerControl.WndProc(Message&m)在System.Windows.Forms.Form.WmShowWindow(Message&m)在System.Windows.Forms.Form.WndProc(Message&m)在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&m)在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m)在System.Windows.Forms.NativeWindow.Callback(IntPtrhWnd,Int32msg,IntPtrwparam,IntPtrlparam)*******************************************************************************全文代码如下:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingGasBusiness;usingSystem.IO;usingSystem.Web.Configuration;usingSystem.Configuration;usingGasBusiness.Beans;usingSystem.Data.SqlClient;namespaceGasManpowerMeasurePoint{publicpartialclassMainForm:Form{privatePagepage=newPage(100);privatestringColumnValue0="";privatestringColumnValue1="";privatestringColumnValue2="";privatestringColumnValue3="";privatestringColumnValue4="";privatestringColumnValue5="";privatestringColumnValue6="";privatestringColumnValue7="";privatestringColumnValue8="";privatestringColumnValue9="";privatestringstrsql;privatestringstrServer="";privatestringstrDatabase="";privatestringstrUserName="";privatestringstrPassword="";publicMainForm(){InitializeComponent();}///<summary>///取得内置的应用程序配置///</summary>///<returns>内置的应用程序配置</returns>privatestaticConfigInfoGetAppConfiguration(){try{returnGasUtils.LoadConfigInfo();}catch{returnnewConfigInfo();}}//取得配置文件里的数据库设置privatevoidGetConfig(){ConfigInfogasConfig=GetAppConfiguration();strServer=gasConfig.DatabaseHost.ToString();strDatabase=gasConfig.DatabaseName.ToString();strUserName=gasConfig.DatabaseUid.ToString();strPassword=gasConfig.DatabasePwd.ToString();}privatestaticDataTableGetData(stringsqlCommand){ConfigInfogasConfig=GetAppConfiguration();stringconnectionString="IntegratedSecurity=SSPI;"+"PersistSecurityInfo=False;"+"InitialCatalog="+gasConfig.DatabaseName.ToString()+";DataSource="+gasConfig.DatabaseHost.ToString();SqlConnectionnorthwindConnection=newSqlConnection(connectionString);SqlCommandcommand=newSqlCommand(sqlCommand,northwindConnection);SqlDataAdapteradapter=newSqlDataAdapter();adapter.SelectCommand=command;DataTabletable=newDataTable();table.Locale=System.Globalization.CultureInfo.InvariantCulture;adapter.Fill(table);returntable;}privatevoidMainForm_Load(objectsender,EventArgse){Data_refresh();}publicvoidData_refresh(){GetConfig();SqlConnectioncon;con=newSqlConnection("DataSource="+strServer+";InitialCatalog="+strDatabase+";UserID="+strUserName+";Password="+strPassword);con.Open();dataGridView1.DataSource=GetData("select*fromtblManpowerMeasurePoint");con.Close();dataGridView1.Columns[0].Visible=false;dataGridView1.Columns[1].HeaderText="班次";dataGridView1.Columns[2].HeaderText="测点编号";dataGridView1.Columns[3].HeaderText="测点名称";dataGridView1.Columns[4].HeaderText="选择时间";dataGridView1.Columns[5].HeaderText="检测人员";dataGridView1.Columns[6].HeaderText="瓦斯浓度";dataGridView1.Columns[7].HeaderText="所在巷道";dataGridView1.Columns[8].HeaderText="巷道编号";dataGridView1.Columns[9].HeaderText="离巷道入口距离";}}}
解决方案
解决方案二:
找不到引用,编译下
解决方案三:
你要不要测试一下,你打包前生成的exe文件.如果没问题的话就是打包的时候出了问题.
解决方案四:
写错了,是C#程序。有高人指点一下吗?程序跟踪也没错啊。
解决方案五:
运行打包前生成的exe文件是正确的。其实程序很简单,就是往SQlServer数据库里写数据。搞不清为什么程序打包后有异常,数据库也链接了。
解决方案六:
帖子要沉了。
解决方案七:
感觉应该是config文件的问题。把你调试用的config文件复制到部署后的目录里,看是不是就没有错了?