I am not sure where have i done the mistake.
I created Windows form in which some controls like combo box populates from the Access Database (accdb). When i create the exe file and install in development PC it works fine but when I install it on different pc, windows throws following error. Looks like it is not able to connect to the database but i am not sure though.
Here is the windows unhandled exception error.
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 MozillaProfiler.MozillaProfiler.getProfiles()
at MozillaProfiler.MozillaProfiler.button2_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.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.18444 built by: FX451RTMGDR
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
MozillaProfiler
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Program%20Files%20(x86)/Smart%20Business%20Telecom/Mozilla%20Profiler/MozillaProfiler.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
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.18408 built by: FX451RTMGREL
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.18408 built by: FX451RTMGREL
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Data
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
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.18408 built by: FX451RTMGREL
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.DirectoryServices
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.DirectoryServices/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.DirectoryServices.dll
----------------------------------------
System.Configuration
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
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.18408 built by: FX451RTMGREL
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Transactions
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Transactions/v4.0_4.0.0.0__b77a5c561934e089/System.Transactions.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:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
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.
What is the actual problem. Do i need to install Microsoft Access Database Engine in the pc where i am installing the application or there is some other alternative to this.
Button2 Event Handler Code
private void button2_Click(object sender, EventArgs e)
{
if (comboBox2.SelectedItem != null)
{
button4.Visible = true;
button5.Visible = true;
label9.Visible = true;
comboBox3.Visible = true;
label14.Visible = false;
progressBar1.Visible = false;
DataSet ds = getProfiles();
if (ds.Tables.Count > 0)
{
comboBox3.DataSource = ds.Tables[0];
comboBox3.DisplayMember = "identifier";
}
// CaluculateAll(progressBar1);
string[] str = comboBox2.Text.Split(' ');
string username = str[2].Replace("[", "").Replace("]", "");
string server1Path = @"\\192.168.1.32\C$\Users\" + username;
string server3Path = @"\\192.168.1.40\C$\Users\" + username;
string server2Path = @"\\192.168.1.33\C$\Users\" + username;
string server4Path = @"\\192.168.1.34\C$\Users\" + username;
string server1Mozilla = @"\\192.168.1.32\C$\Users\" + username + @"\AppData\Roaming\Mozilla";
string server3Mozilla = @"\\192.168.1.40\C$\Users\" + username + @"\AppData\Roaming\Mozilla";
string server2Mozilla = @"\\192.168.1.33\C$\Users\" + username + @"\AppData\Roaming\Mozilla";
string server4Mozilla = @"\\192.168.1.34\C$\Users\" + username + @"\AppData\Roaming\Mozilla";
if (Directory.Exists(server1Path)) { pictureBox1.BackColor = Color.Green; } else { pictureBox1.BackColor = Color.Red; }
if (Directory.Exists(server2Path)) { pictureBox2.BackColor = Color.Green; } else { pictureBox2.BackColor = Color.Red; }
if (Directory.Exists(server3Path)) { pictureBox3.BackColor = Color.Green; } else { pictureBox3.BackColor = Color.Red; }
if (Directory.Exists(server4Path)) { pictureBox4.BackColor = Color.Green; } else { pictureBox4.BackColor = Color.Red; }
if (Directory.Exists(server1Mozilla)) { pictureBox5.BackColor = Color.Green; } else { pictureBox5.BackColor = Color.Red; }
if (Directory.Exists(server2Mozilla)) { pictureBox6.BackColor = Color.Green; } else { pictureBox6.BackColor = Color.Red; }
if (Directory.Exists(server3Mozilla)) { pictureBox7.BackColor = Color.Green; } else { pictureBox7.BackColor = Color.Red; }
if (Directory.Exists(server4Mozilla)) { pictureBox8.BackColor = Color.Green; } else { pictureBox8.BackColor = Color.Red; }
if (pictureBox1.BackColor == Color.Green) { server1Profile.Enabled = false; server1Check.Enabled = true; } else { server1Profile.Enabled = true; server1Check.Enabled = false; }
if (pictureBox2.BackColor == Color.Green) { server2Profile.Enabled = false; server2Check.Enabled = true; } else { server2Profile.Enabled = true; server2Check.Enabled = false; }
if (pictureBox3.BackColor == Color.Green) { server3Profile.Enabled = false; server3Check.Enabled = true; } else { server3Profile.Enabled = true; server3Check.Enabled = false; }
if (pictureBox4.BackColor == Color.Green) { server4Profile.Enabled = false; server4Check.Enabled = true; } else { server4Profile.Enabled = true; server4Check.Enabled = false; }
if ((server1Profile.Enabled == false) && (server2Profile.Enabled == false) && (server3Profile.Enabled == false) && (server4Profile.Enabled == false)) { button4.Visible = false; }
}
else
{
MessageBox.Show("No user selected");
}
}
public DataSet getProfiles()
{
conn.ConnectionString = ConfigurationManager.ConnectionStrings["dbConnector"].ToString();
DataSet dataSet = new DataSet();
try
{
conn.Open();
string sql = "SELECT [identifier] FROM [MozillaData]";
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(sql, conn);
dataAdapter.Fill(dataSet, "MozillaData");
}
catch (Exception)
{
MessageBox.Show("Database Error");
}
finally
{
conn.Close();
}
if (dataSet.Tables["MozillaData"].Rows.Count <= 0)
return null;
return dataSet;
}