Error on session.CompareDatabases
Brian Donahue
Posts: 6,590 Bronze 1
Hi Ian,
I'm not 100% sure what the whole story is there, but I'd say that it's
because you need to have the ORDER_NUMBER column present in both databases'
tables before you try to compare them.
Regards,
Brian Donahue
Red Gate Technical Support
"Ian Spence" <ian.spence@ebooks.com> wrote in message
news:xVBtgGkQEHA.3156@server53...
> I am getting this error when a column ORDER_NUMBER has been added to one
> table but does not exist (yet) on the second database. Any ideas ? This
> code was working fine before someone added a column on the first database.
>
>
> Unhandled Exception: System.Data.SqlClient.SqlException: Invalid column
name
> 'ORDER_NUMBER'.
> at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
> cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at
> System.Data.SqlClient.SqlCommand.ExecuteReader() at ?.Open()
> Unhandled Exception: System.Data.SqlClient.SqlException: Invalid column
name
> 'ORDER_NUMBER'.
> at RedGate.SQLDataCompare.Engine.ComparisonSession.?(ITableReader& ,
> ITableReader& , Database , Database , Object , Object ,
> TableComparisonSetting )
> at
> RedGate.SQLDataCompare.Engine.ComparisonSession.CompareDatabases(Database
> database1, Database database2, TableComparisonSettings tablesToCompare,
> SessionSettings sessionSettings)
> at
> RedGate.SQLDataCompare.Engine.ComparisonSession.CompareDatabases(Database
> database1, Database database2, TableComparisonSettings tablesToCompare)
> at SQLDataCompareCodeSnippets.Class1.SynchronizeDatabases() in
> c:developmentworkptisyncptisyncptisyncclass1.cs:line 156
> at SQLDataCompareCodeSnippets.Class1.Main(String[] args) in
> c:developmentworkptisyncptisyncptisyncclass1.cs:line 68
>
>
> for this piece of code
>
>
> Tables commonTables = db1.Tables;
>
> //set up the table comparison setting
>
> TableComparisonSettings settings=new TableComparisonSettings();
>
> // This is a workaround as table.primarykey is returning null
>
> foreach (Table table in commonTables)
>
> {
>
> Console.WriteLine(table.FullyQualifiedName);
>
> Index primaryKeyIndex = null;
>
> System.Collections.IEnumerator enumerator = table.Indexes.GetEnumerator();
>
> try
>
> {
>
> while (enumerator.MoveNext())
>
> {
>
> Index element = (Index)enumerator.Current;
>
> if (element.IsPrimary)
>
> {
>
> primaryKeyIndex = element;
>
> Console.WriteLine(element.Name + " " + element.IsPrimary);
>
> break;
>
> }
>
> }
>
> }
>
> finally
>
> {
>
> IDisposable disposable = enumerator as System.IDisposable;
>
> if (disposable != null) disposable.Dispose();
>
> }
>
> if (primaryKeyIndex != null)
>
> {
>
> settings.Add(new TableComparisonSetting(table.FullyQualifiedName,
> table.Fields, primaryKeyIndex.Fields));
>
> }
>
> else
>
> {
>
> Console.WriteLine(table.FullyQualifiedName + " could not determine primary
> key.");
>
> }
>
> }
>
> session.CompareDatabases(db1, db2, settings);
>
>
I'm not 100% sure what the whole story is there, but I'd say that it's
because you need to have the ORDER_NUMBER column present in both databases'
tables before you try to compare them.
Regards,
Brian Donahue
Red Gate Technical Support
"Ian Spence" <ian.spence@ebooks.com> wrote in message
news:xVBtgGkQEHA.3156@server53...
> I am getting this error when a column ORDER_NUMBER has been added to one
> table but does not exist (yet) on the second database. Any ideas ? This
> code was working fine before someone added a column on the first database.
>
>
> Unhandled Exception: System.Data.SqlClient.SqlException: Invalid column
name
> 'ORDER_NUMBER'.
> at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
> cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at
> System.Data.SqlClient.SqlCommand.ExecuteReader() at ?.Open()
> Unhandled Exception: System.Data.SqlClient.SqlException: Invalid column
name
> 'ORDER_NUMBER'.
> at RedGate.SQLDataCompare.Engine.ComparisonSession.?(ITableReader& ,
> ITableReader& , Database , Database , Object , Object ,
> TableComparisonSetting )
> at
> RedGate.SQLDataCompare.Engine.ComparisonSession.CompareDatabases(Database
> database1, Database database2, TableComparisonSettings tablesToCompare,
> SessionSettings sessionSettings)
> at
> RedGate.SQLDataCompare.Engine.ComparisonSession.CompareDatabases(Database
> database1, Database database2, TableComparisonSettings tablesToCompare)
> at SQLDataCompareCodeSnippets.Class1.SynchronizeDatabases() in
> c:developmentworkptisyncptisyncptisyncclass1.cs:line 156
> at SQLDataCompareCodeSnippets.Class1.Main(String[] args) in
> c:developmentworkptisyncptisyncptisyncclass1.cs:line 68
>
>
> for this piece of code
>
>
> Tables commonTables = db1.Tables;
>
> //set up the table comparison setting
>
> TableComparisonSettings settings=new TableComparisonSettings();
>
> // This is a workaround as table.primarykey is returning null
>
> foreach (Table table in commonTables)
>
> {
>
> Console.WriteLine(table.FullyQualifiedName);
>
> Index primaryKeyIndex = null;
>
> System.Collections.IEnumerator enumerator = table.Indexes.GetEnumerator();
>
> try
>
> {
>
> while (enumerator.MoveNext())
>
> {
>
> Index element = (Index)enumerator.Current;
>
> if (element.IsPrimary)
>
> {
>
> primaryKeyIndex = element;
>
> Console.WriteLine(element.Name + " " + element.IsPrimary);
>
> break;
>
> }
>
> }
>
> }
>
> finally
>
> {
>
> IDisposable disposable = enumerator as System.IDisposable;
>
> if (disposable != null) disposable.Dispose();
>
> }
>
> if (primaryKeyIndex != null)
>
> {
>
> settings.Add(new TableComparisonSetting(table.FullyQualifiedName,
> table.Fields, primaryKeyIndex.Fields));
>
> }
>
> else
>
> {
>
> Console.WriteLine(table.FullyQualifiedName + " could not determine primary
> key.");
>
> }
>
> }
>
> session.CompareDatabases(db1, db2, settings);
>
>
This discussion has been closed.