Red Gate forums :: View topic - Null Reference Exception
Return to RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SQL Toolkit Previous Versions
SQL Toolkit Previous Versions forum

Null Reference Exception

Search in SQL Toolkit Previous Versions forum
Post new topic   Reply to topic
Jump to:  
Author Message

Joined: 05 Dec 2007
Posts: 1

PostPosted: Wed Dec 05, 2007 10:33 pm    Post subject: Null Reference Exception Reply with quote

I am using Vb.Net and testing the SQL DataCompare API but it gives null reference exception for the object of time tabledifference. please help . Here is the code. I have bolded the line where i am getting the error:

Dim VW_Dev As New Database
Dim VW_Stage As New Database
VW_Dev.RegisterForDataCompare(New ConnectionProperties("SQL-31LI\Development", "widget_dev", "sqldba", "abc"))
VW_Stage.RegisterForDataCompare(New ConnectionProperties(".", "widget"))

Dim mappings As New SchemaMappings
mappings.CreateMappings(VW_Dev, VW_Stage)

Dim session As New ComparisonSession()
session.CompareDatabases(VW_Dev, VW_Stage, mappings)

Dim mapping As TableMapping
For Each mapping In mappings.TableMappings
Dim table As ViewTableSuperClass = mapping.Obj1
Dim difference As TableDifference = session.TableDifferences(table.FullyQualifiedName)
Dim row As Row
For Each row In difference.ResultsStore 'loop through all the rows
If (row.Type <> row.RowType.Same) Then 'go through the non same records
Dim field As FieldPair
Dim i As Int32 = 0
Console.WriteLine("{0} Row {1} type {2}", table.FullyQualifiedName, row.Index, row.Type.ToString())
For Each field In difference.ResultsStore.Fields
'work out where about in the results the field data is stored
'if we were comparing identical records, or records present in one
'database but not the other then we would not need to
'use the OrdinalInResults1 and OrdinalInResults2 properties
'but just OrdinalInResults
Dim field1 As Int32 = field.OrdinalInResults1
Dim field2 As Int32 = field.OrdinalInResults2

If (field1 <> field2) Then
'get the values
Dim value1 As Object = row.Values(field1)
Dim value2 As Object = row.Values(field2)
If (value1 Is Nothing) Then
value1 = "NULL"
End If
If (value2 Is Nothing) Then
value2 = "NULL"
End If
If row.FieldDifferent(i) Then
Console.WriteLine("{0}:{1} <> {2}", field.Field(False).Name, value1.ToString(), value2.ToString())
Console.WriteLine("{0}:{1} == {2}", field.Field(False).Name, value1.ToString(), value2.ToString())
End If
'this is part of the unique index we are comparing on
Dim value As Object = row.Values(field1)
Console.WriteLine("*{0}:{1}", field.Field(False).Name, value.ToString())
End If
i += 1
End If

'Get the synchronization SQL
Dim provider As New SqlProvider
'we want to run the SQL on Vitaminworld so pass in true as the second parameter


End Sub
Back to top
View user's profile Send private message
Brian Donahue

Joined: 23 Aug 2004
Posts: 6677

PostPosted: Thu Dec 06, 2007 10:36 am    Post subject: Reply with quote

Thanks for your post. I can't say what the problem is, but here is a tip: try setting some breakpoints and using the immediate window to figure out which object is NULL. For instance, mapping.obj1 could be null if the object does not exist in database 1. Or there could be some wierdness causing table.FullyQualifiedName to be null. Either of these could have the effect of returning a NULL resultsstore object.

I think it is possible for a mapping to be partial -- that is the mapping may not have a matching table or view in either database, so maybe checking each mapping's .include property first would be a good way to prevent this situation. If the mapping is included, chances are the object does exist in both databases and can be compared.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2005 phpBB Group