0

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.

3
  • 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. Commented Apr 9, 2013 at 23:38
  • @kadumel How can I make the security avaliable so all of they can be accesseed? The target machine uses XP Commented Apr 9, 2013 at 23:40
  • 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 Commented Apr 9, 2013 at 23:41

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you for your answer. I have added the Users folder myself on the XP machine and this is where the access DB file is. So it is in theory at that connection path. Do i need to rename the connection path of the .exe file?
As long as the database file can be found at the second machine exactly at C:\Users\Dave\Documents\duraGadget.mdb then it should be okay. Maybe next time you can add the database file to the same directory as your exe, or even better, install sql server express and access the database instead of a database-file
@Amegon Thanks for your reply. This is going to sound very simple in theory but eventually the database will reside at the location Z:\Sku\duraGadget.mdb. Now is this a case of simply changing my connection strings? Also I dont know in this case if it makes any difference but my database is split. I have a duraGadget.mdb and a duraGadget_be.mdb. Should I be pointing at the backend copy?
@user1352057 hmm I guess any solution that allows you to use the same connection string at both PCs would be good. So a real sql server is good, since the connection string contains the pc name (does not matter which one executes it), and I guess if you stick to a database-file, then to update it to a network path is also an improvement. But be sure that windows security rules will not disallow reading and writing to it. And make sure that the other pc also linked the network path the same way, even when it is from itself. So you have less worries. I am sorry, I have no idea about the backend
@user1352057 you need to have the .mdb file exactly where your connection string's source points. It's up to you if you want to make your string point to a known location or if you want to create the folder it points. The only important thing is: the .mdb file needs to be there.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.