nullref while querying indexes collection


Gonna see if I can single step it and work out what is causing this..
Open DBDiff Beta
Error Loading Destination Database (while Reading Index: [index_Messages_AuthorID_DeletedOn])
NullReferenceException: Object reference not set to an instance of an object.
   at DBDiff.Schema.SQLServer.Generates.Generates.GenerateIndex.Fill(Database database, String connectionString) in C:\Users\cjard\Documents\Visual Studio 2010\Projects\VisionsLive\mercurial\AssortedUtilities\OpenDBDiff\DBDiff.Schema.SQLServer2005\Generates\GenerateIndex.cs:line 60
   at DBDiff.Schema.SQLServer.Generates.Generates.Generate.Process() in C:\Users\cjard\Documents\Visual Studio 2010\Projects\VisionsLive\mercurial\AssortedUtilities\OpenDBDiff\DBDiff.Schema.SQLServer2005\Generates\Generate.cs:line 99
   at DBDiff.Front.ProgressForm.ProgressForm_Activated(Object sender, EventArgs e) in C:\Users\cjard\Documents\Visual Studio 2010\Projects\VisionsLive\mercurial\AssortedUtilities\OpenDBDiff\DBDiff\Front\ProgressForm.cs:line 96
Closed Feb 19, 2015 at 7:04 AM by jspraul
This error may be resolved by connecting to the database with higher permissions; Open DBDiff is unable to find the parent object of the specified index.

Closing this as a duplicate of issue #15406.


cjard wrote Mar 5, 2013 at 4:07 PM

Around line 190 of GenerateTables we find:
col.DefaultConstraint = new ColumnConstraint(col)
                                                Id = (int) reader[colDefaultIdIndex],
                                                Owner = table.Owner,
                                                Name = (string) reader[colDefaultNameIndex],
                                                Type = Constraint.ConstraintType.Default,
                                                Definition = (string) reader[colDefaultDefinitionIndex]
The problem is with "Definition = " - for reasons unknown my database has NULL for this particular row/column and DBNull cannot be cast to string.

I simply .ToString()ed it..

Is it sensible/expected that the definition of the default value for a column will be null?

jspraul wrote Mar 6, 2013 at 7:29 PM

Perhaps unusual but obviously possible; most fixes thus far have been more about avoiding crashes.