0
votes

My scenario is I have created a VB.NET application on my development machine and now wish to use the package and deployment wizard to distribute it to another machine.

The code on the development machine works perfectly, but when I install it on the target machine it is giving a null reference exception.

I have an access database on the target machine which is an exact copy of the DB ive been using on my development machine. My connection string is defined in my app.config file and am at a loss of how to proceed.

This is my app.config file which houses my connection string:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
  <add name="connString"
       connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Dave\Documents\duraGadget.mdb"
       providerName="System.Data.OleDb" />
</connectionStrings>
<startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />
</startup>
</configuration>

This is my Form1 load (where the null pointer is occurring according to the error message):

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    constring = ConfigurationManager.ConnectionStrings("connString").ConnectionString()

    Dim sql As String = "SELECT * FROM duragadget ORDER BY skuNo ASC"
    Dim connection As New OleDbConnection(constring)
    Dim dataadapter As New OleDbDataAdapter(sql, connection)
    Dim ds As New DataSet()
    connection.Open()
    dataadapter.Fill(ds, "dura")
    connection.Close()
    DataGridView1.DataSource = ds
    DataGridView1.DataMember = "dura"

    DataGridView1.Columns(1).Width = 125
    DataGridView1.Columns(2).Width = 125
    DataGridView1.Columns(3).Width = 125
    DataGridView1.Columns(4).Width = 125
    DataGridView1.Columns(5).Width = 5000

End Sub

Here is the error message as shown in the dialog of the error message box on the target machine:

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 DuraGadget.Form1.Form1_Load(Object sender, EventArgs e) at System.EventHandler.Invoke(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.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.296 (RTMGDR.030319-2900)

CodeBase: file:///c:/WINDOWS/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll

DuraGadget Assembly Version: 1.0.0.0 Win32 Version: 1.0.0.0

CodeBase: file:///C:/Program%20Files/Default%20Company%20Name/DSN%20new%20Upgrade/DuraGadget.exe

Microsoft.VisualBasic Assembly Version: 10.0.0.0 Win32 Version: 10.0.30319.1 built by: RTMRel

CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll

System Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.1001 built by: RTMGDR

CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll

System.Core Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.1 built by: RTMRel

CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll

System.Windows.Forms Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.1002 built by: RTMGDR

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.1001 built by: RTMGDR

CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll

System.Runtime.Remoting Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)

CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Remoting/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll

System.Data Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)

CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll

System.Configuration Assembly Version: 4.0.0.0 Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)

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.1 built by: RTMRel

CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.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.

2
Are you sure that wherever your application is running from that you have access to a user folder? Most of the time user folders are locked from being available, depending on which version of Windows you are using. - PW Kad
@kadumel How can I make the security avaliable so all of they can be accesseed? The target machine uses XP - user1352057
Put your database in C:\ and see if you can hit it then. If you can then that is probably the issue. If not still then there is another problem. If that is the case then you will need to edit the permissions for that folder - PW Kad

2 Answers

1
votes

Here's the source in your connection string:

Data Source=C:\Users\Dave\Documents\duraGadget.mdb

The path to your exe on your machine:

C:/Program Files/Default Company Name/DSN new Upgrade/DuraGadget.exe

Most probably the duraGadget file can't be opened because there does not exists in the specified folder (on the target machine) because the C:\Users\Dave directory does not exists altogether. You said it is a Windows XP, XP does not have C:\Users folder. So yeah. Update your connection string's path.

0
votes

Guys thanks for all your suggestion. I got this cracked in the end after many hours of working on it. It was a combination of things. To anybody who is in a similar situation, use the publish option by right clicking your project folder... properties then publish for one click deployment throught the publish wizard. Also I'm using a different database. The split database was causing me trouble and isn't needed in my case. Changing these issues along with declaring a single connection string in my app.config, along with ensuring my dataset connection string was correctly setup FINALLY sorted it and I can now install it on XP...Win7 etc.