0

I have developed an application in C#.NET using SQL SERVER LocalDB 2012. Now application runs fine on pressing F5 (means in visual studio development environment) . But when I try to install this application on my local PC or in Vmware machine, it gives Null Object reference error as

object reference not set to an instance of an object See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text ************** System.NullReferenceException: Object reference not set to an instance of an >object. at intermediateProject.main.Form1_Load(Object sender, EventArgs e) at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Form.OnCreateControl() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ContainerControl.WndProc(Message& m) at System.Windows.Forms.Form.WmShowWindow(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

************* Loaded Assemblies ************** mscorlib Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.34209 built by: FX452RTMGDR CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll --------------------------------------- Agri Foods Assembly Version: 1.0.0.0 Win32 Version: 1.0.0.0 CodeBase: file:///C:/Program%20Files%20(x86)/cokeStudio/My%20Product%20Name/Agri%20Foods.exe --------------------------------------- System.Windows.Forms Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.34250 built by: FX452RTMGDR CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll -------------------------------------- System.Drawing Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.36337 built by: FX452RTMLDR CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll ----------------------------------- System Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.34239 built by: FX452RTMGDR CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll --------------------------------------- System.Configuration Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.34209 built by: FX452RTMGDR CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0>0.0__b03f5f7f11d50a3a/System.Configuration.dll --------------------------------------- System.Xml Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.34281 built by: FX452RTMGDR CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll --------------------------------------- System.Data Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.34209 built by: FX452RTMGDR CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll --------------------------------------- System.Core Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.34209 built by: FX452RTMGDR CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll --------------------------------------- System.Data.DataSetExtensions Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.33440 built by: FX45W81RTMREL CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Data.DataSetExtensions/v4.0_4.0.0.0__b77a5c561934e089/System.Data.DataSetExtensions.dll --------------------------------------- System.Numerics Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.34209 built by: FX452RTMGDR CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Numerics/v4.0_4.0.0.0__b77a5c561934e089/System.Numerics.dll --------------------------------------- Accessibility Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.33440 built by: FX45W81RTMREL

CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll

************* JIT Debugging ************** To enable just-in-time (JIT) debugging, the .config file for this application or computer (machine.config) must have the jitDebugging value set in the system.windows.forms section. The application must also be compiled with debugging enabled.

For example:

When JIT debugging is enabled, any unhandled exception will be sent to the JIT debugger registered on the computer rather than be handled by this dialog box.

object reference not set to an instance of an object....

I have tried to add Database Project also but could not find it use full .

[1]:

https://i.stack.imgur.com/n9cjq.png

I am using the connection string as follows:

    <connectionStrings>
    <add name="ConString" connectionString="Data Source=.\SQLExpress;       Initial Catalog=test;Integrated Security=True"
         providerName="System.Data.SqlClient" />

     </connectionStrings>

And Also the form load code is as follows:

     private void Form1_Load(object sender, EventArgs e)
    {
          SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString);

         DataTable dt = new DataTable();
        SqlDataAdapter sda = new SqlDataAdapter("select * from fianlTable", con);
         sda.Fill(dt);
         dataGridView1.DataSource = dt;

       }
  • Can you post your code in the Form1_Load? – Dr. Stitch Apr 22 '16 at 07:32
  • Dr. Stitch Plz review the code as I have added my connection string and also I have edited my database to SQLEXPRESS. I am having trouble when I make setup installer . When I run the code it runs fine on Visual Studio runtime. You can see Form1_Load code with reference to connection string. Thanks – Muhammad Shahid – Muhammad Shahid Apr 22 '16 at 21:34

0 Answers0