0

Can anybody explain to me why the following sub on the development machine runs smoothly, but when I deploy and install on another pc I get an error.

The Error I get is "Couldnt show any because: Object reference not set to an instance of an object"

While on the development machine it works. Both running Win7, I inclluded all sql files as stated on the deployment instruction for datafile and sql-ce dll's from the msdn.

The datafile is fine and connection is good, becuase a "cmd.ExecuteNonQuery()" runs without problems.

Public Sub LoadFolders()
    Dim ds As New DataSet
    Dim da As SqlCeDataAdapter = New SqlCeDataAdapter()
    Dim cmd As SqlCeCommand



    Try
        cmd = New SqlCeCommand("SELECT distinct(folder) from addressbook", connection.DbPrivate)
        cmd.CommandType = Data.CommandType.Text
    Catch e As Exception
        Console.WriteLine("Could not execute sql: {0}", e.Message)
    End Try



    Try
        With da
            .SelectCommand = cmd
            .Fill(ds, "folders")
        End With

    Catch e As Exception
        Console.WriteLine("Unable to fill dataset: {0}", e.Message)
    End Try

    Try
        For Each irow As DataRow In ds.Tables("folders").Rows
            MsgBox(irow(0))
        Next
    Catch e As Exception
        MsgBox("Couldnt show any because: " + e.Message) 'this is the error that pops up.
    End Try


End Sub
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
renevdkooi
  • 1,515
  • 1
  • 17
  • 42
  • This is something you can determine quite easily with your debugger: either `ds` is null or there is no table called *folders* (or it is null), or the fields collection of `irow` is null. Now IIRC the `.Rows` and `.Fields` collection should never be null, which leaves only a couple of options. – slugster Feb 29 '12 at 08:48
  • on my dev machine the debugger gives no errors. but When installed on another machine. And the error window on the other machine doesn't give much info. (how would I debug on that machine? sorry for a stupid q) – renevdkooi Feb 29 '12 at 08:51
  • Obviously the SQLCE database on the second machine has different data to that on your dev machine, hence the different result. Either build in more null checks and redeploy to the target machine, or grab the databse from the target and use it on your dev machine with your debugger (this is probably the simplest and quickest solution). – slugster Feb 29 '12 at 09:17
  • possible duplicate of [What is a NullReferenceException in .NET?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net) – John Saunders Feb 29 '12 at 09:31
  • 1
    Use e.StackTrace instead e.Message to see code line error – Amen Ayach Feb 29 '12 at 10:10
  • no matter how many checks i put on it, and no matter if i copied the working version of the databse it just won't work, it keeps returning the same message. When I do other checks like if the table exists, by looking at the info_schema_tables I get the table back. When I ask for the table structure, all is good. When the result set is empty on the dev machine it continues and tells me 0 rows found, but the other machine just comes with this error. – renevdkooi Feb 29 '12 at 10:11
  • http://www.mind-zone.nl/tmp.rar to see... (extract of the whole project, this works flawless on the dev machine and crashes on another machine) – renevdkooi Feb 29 '12 at 10:21

2 Answers2

0

I think your problem might be in the connection string, make sure it is right and then check if you had included any references that they are included on the other pc.

Alex
  • 5,971
  • 11
  • 42
  • 80
  • Well I am confused now... I have made some changes to it, but the moment I installed Office on the other machine everything worked fine. And when I use VB to Attach to Process to my dev machine I still get some casting errors, though when the app is installed on the other pc and I attach to that source, no errors come up... weird... not sure if it was the connection or office... – renevdkooi Mar 01 '12 at 02:57
0

What the problem was I still do not know. But here is how I solved it.

I opened up a new project. Added database sources (which were the sql compact database files from the project that wasn't working) then followed the steps to create COnnection, dataAdapter and dataset Settings were then saved in the my project - settings variables.

I then dragged 7 compact sql files (sqlce*.dll) into my project and set to copy when newer. Then in the My Project - publish tab under "application files" i made sure they were included and my data files were set to DATA

Also prerequisites was framework 3.5 and sql ce 3.5. Now I can access all data...very very weird...

renevdkooi
  • 1,515
  • 1
  • 17
  • 42