DAAB 3.0 "Object reference not set to an instance of an object."

Topics: Data Access Application Block
Jun 7, 2007 at 9:59 PM
Edited Jun 7, 2007 at 10:00 PM
i get an error at the db = DatabaseFactory.CreateDatabase();
could you tell me what am i missing?

System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)
public HydEntGeneralInfo Get(System.Int32 jobID)
{
DataSet ds;
Database db;
string sqlCommand;
DbCommand dbCommand;
HydEntGeneralInfo instance;

instance = new HydEntGeneralInfo();

db = DatabaseFactory.CreateDatabase();
sqlCommand = "dbo.gspHydEntGeneralInfo_SELECT";
dbCommand = db.GetStoredProcCommand(sqlCommand, jobID);

// Get results.
ds = db.ExecuteDataSet(dbCommand);
// Verification.
if (ds == null || ds.Tables0.Rows.Count == 0) throw new ApplicationException("Could not get HydEntGeneralInfo ID:" + jobID.ToString() + " from Database.");
// Return results.
ds.Tables0.TableName = TABLE_NAME;

instance.MapFrom(ds.Tables0.Rows0);
return instance;
}

*********app.config file***************
<configuration>
<configSections>
<section name="dataConfiguration"
type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data" />
</configSections>
<dataConfiguration defaultDatabase="Connection String"/>
<connectionStrings>
<add name="Connection String"
connectionString="Database=ypdata5sql;Server=compname\SQLEXPRESS;Integrated Security=SSPI"
providerName="System.Data.SqlClient" />
<add name="Default"
connectionString="Data Source=computername\SQLEXPRESS;Initial Catalog=ypdata5sql;Integrated Security=SSPI"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
Jun 8, 2007 at 1:30 AM
Maybe the app.config you are displaying is not in the root directory of your application which is where Enterprise Library is expecting it given the code above.

Regards,

Dave

____________________________

David Hayden
Microsoft MVP C#

Jun 8, 2007 at 2:42 PM
I still get the same error.

I moved the config file to root directory of the project and also had it in the root directory of the solution.

how does the projectname.dll.config file created in the bin/debug folder?


Jun 9, 2007 at 3:23 PM
Not the root directory of the class library. It must be in the root directory of the application.

Enterprise Library won't pick up any settings in projectname.dll.config unless you use IConfigurationSource.

It is lookling for Enterprise Library settings in web.config in the root directory of the web application or the myapplication.exe.config file.

Regards,

Dave

_______________________________

David Hayden
Microsoft MVP C#
Jun 12, 2007 at 6:13 PM
I changed the App.config in the root directory of the application.

i am also using
FileConfigurationSource fileSource = new FileConfigurationSource(@"..\..\App.config");
made sure its pointing to my App.config in the application not the class library..

but now i get this error:

Could not load file or assembly 'Microsoft.Practices.ObjectBuilder, Version=1.0.51206.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"Microsoft.Practices.ObjectBuilder, Version=1.0.51206.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Jun 12, 2007 at 7:01 PM
I think this is happening b'cau i am using CAB also.

CAB is using objectbuilder with version 1.0.51205.0
and enterprise library is using objectbuilder version 1.0.51206.0.

so what is the resolution for this. so we cannot use enterprise library 3.0 if we are using CAB?
Jun 12, 2007 at 7:18 PM
Edited Jun 12, 2007 at 7:30 PM
I can make it work in a simple windows application. but not able work this in a CAB application.
I guess it is b'cau of the objectBuilder.dll having 2 different versions.

how can i make these two work together.. any clues please....
Jun 12, 2007 at 10:22 PM
finally worked thanks to the following link

http://savij.com/2007/05/25/cab-enterprise-library-3-and-scsf-errors/