Sunday, January 31, 2010

NDbUnit- Invalid object name

For our integration testing, we are using NDbUnit, a free open source .NET library for managing database state during testing. It ensures that our database is always in a consistent state before we start the execution of our tests. It uses an XSD schema to describe the database tables and an XML file can be used to provide the content.

After configuring everything, we initialized our database using following code

   1:  var mySqlDatabase = new NDbUnit.Core.SqlClient.SqlDbUnitTest(@"server=;user=;password=;initial catalog=");
   2:  mySqlDatabase.ReadXmlSchema(@"./Test.xsd");
   3:  mySqlDatabase.ReadXml("./Data.xml");
   4:  mySqlDatabase.PerformDbOperation(NDbUnit.Core.DbOperationFlag.CleanInsertIdentity);

But instead of populating our database with the correct values, we got an Invalid Object Name exception for each table. We found out that NDbUnit uses the default schema of the user specified in the connection string to look for the tables. So if you are using a different schema NDbUnit will not succeed in executing its scripts.



Something to keep in mind…

1 comment:

Anonymous said...

In the DataSet designer, manually edit the table name to include the schema. For example if the table is 'TestTable', and your schema is 'TestSchema', Change the table name in the designer to 'TestSchema.TestTable'.

Hope that helps.