Enterprise Library error

G

Guest

Hello Everyone,

I downloaded enterprise library 2.0 , 2006 today . I followed all the
instructions that were given in the documentation.
I tried to follow everything that was mentioned in QuickStart samples. I
made a small web application that did everything that Quick start sample was
doing and I can successfully complie the code.
Below is my code. This is the exact code that is written in quick start
samples

Database db = DatabaseFactory.CreateDatabase();
string sqlCommand = "sp_getUserId";
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);

// Retrieve products from the specified category.
db.AddInParameter(dbCommand, "LogOn", DbType.Int32, "abcde2");

// DataSet that will hold the returned results
DataSet productsDataSet = null;

productsDataSet = db.ExecuteDataSet(dbCommand);
return productsDataSet;

The dll's I am including are
using System.Web.UI.HtmlControls;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;

other dll's that come automatically in the project are
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

I am getting a run time error on the first line of the code, Database db =
DatabaseFactory.CreateDatabase();
System.NullReferenceException {"Object reference not set to an instance of
an object."}

In the Quick startsamples they are not passing any parameter in
createDatabase().

Please let me know what am I doing wrong.

Thanks
 
D

DeveloperX

Hello Everyone,

I downloaded enterprise library 2.0 , 2006 today . I followed all the
instructions that were given in the documentation.
I tried to follow everything that was mentioned in QuickStart samples. I
made a small web application that did everything that Quick start sample was
doing and I can successfully complie the code.
Below is my code. This is the exact code that is written in quick start
samples

Database db = DatabaseFactory.CreateDatabase();
string sqlCommand = "sp_getUserId";
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);

// Retrieve products from the specified category.
db.AddInParameter(dbCommand, "LogOn", DbType.Int32, "abcde2");

// DataSet that will hold the returned results
DataSet productsDataSet = null;

productsDataSet = db.ExecuteDataSet(dbCommand);
return productsDataSet;

The dll's I am including are
using System.Web.UI.HtmlControls;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;

other dll's that come automatically in the project are
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

I am getting a run time error on the first line of the code, Database db =
DatabaseFactory.CreateDatabase();
System.NullReferenceException {"Object reference not set to an instance of
an object."}

In the Quick startsamples they are not passing any parameter in
createDatabase().

Please let me know what am I doing wrong.

Thanks

I imagine your config file has an error in it, it gets the connection
string from there. Compare yours with the quick start config.
 
S

sloan

Database db = DatabaseFactory.CreateDatabase();

this loads the "default instance". Look in web.config (or app.config)
There should be a one liner in the xml that has "default instance" or
something like that in there.


Database db = DatabaseFactory.CreateDatabase("myInstance");

this gets a specific instance. this should be the name of the connection
string.
The EntLib developers decided to piggy back off the new 2.0 connection
string stuff, instead of trying to reproduce (or replace it).

...

PS
productsDataSet = db.ExecuteDataSet(dbCommand);
return productsDataSet;

I actually prefer the .LoadDataSet method

//start code
db.LoadDataSet(dbCommand , productsDataSet , new string[]{
"table1", "table2" });
productsDataSet;

because I specifically name the tables. if you have a strong typed dataset,
then the tablenames have to match your strong tablenames of course.
 
G

Guest

Thanks for the help. There was something wrong with my we.config file. now
that I successfully executed the code, I am getting a message or warning that
says "Coukd not find information for the element 'dataConfiguration'. I can
run my code though.

I have another question. In this case I can only use one connectionstring,
the default connection string , can I use multiple connection string in
web.config file if I am extracting data from different database.

Thanks again for all the help.

sloan said:
Database db = DatabaseFactory.CreateDatabase();

this loads the "default instance". Look in web.config (or app.config)
There should be a one liner in the xml that has "default instance" or
something like that in there.


Database db = DatabaseFactory.CreateDatabase("myInstance");

this gets a specific instance. this should be the name of the connection
string.
The EntLib developers decided to piggy back off the new 2.0 connection
string stuff, instead of trying to reproduce (or replace it).

...

PS
productsDataSet = db.ExecuteDataSet(dbCommand);
return productsDataSet;

I actually prefer the .LoadDataSet method

//start code
db.LoadDataSet(dbCommand , productsDataSet , new string[]{
"table1", "table2" });
productsDataSet;

because I specifically name the tables. if you have a strong typed dataset,
then the tablenames have to match your strong tablenames of course.




Vinki said:
Hello Everyone,

I downloaded enterprise library 2.0 , 2006 today . I followed all the
instructions that were given in the documentation.
I tried to follow everything that was mentioned in QuickStart samples. I
made a small web application that did everything that Quick start sample was
doing and I can successfully complie the code.
Below is my code. This is the exact code that is written in quick start
samples

Database db = DatabaseFactory.CreateDatabase();
string sqlCommand = "sp_getUserId";
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);

// Retrieve products from the specified category.
db.AddInParameter(dbCommand, "LogOn", DbType.Int32, "abcde2");

// DataSet that will hold the returned results
DataSet productsDataSet = null;

productsDataSet = db.ExecuteDataSet(dbCommand);
return productsDataSet;

The dll's I am including are
using System.Web.UI.HtmlControls;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;

other dll's that come automatically in the project are
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

I am getting a run time error on the first line of the code, Database db =
DatabaseFactory.CreateDatabase();
System.NullReferenceException {"Object reference not set to an instance of
an object."}

In the Quick startsamples they are not passing any parameter in
createDatabase().

Please let me know what am I doing wrong.

Thanks
 
D

DeveloperX

Thanks for the help. There was something wrong with my we.config file. now
that I successfully executed the code, I am getting a message or warning that
says "Coukd not find information for the element 'dataConfiguration'. I can
run my code though.

I have another question. In this case I can only use one connectionstring,
the default connection string , can I use multiple connection string in
web.config file if I am extracting data from different database.

Thanks again for all the help.



sloan said:
Database db = DatabaseFactory.CreateDatabase();
this loads the "default instance". Look in web.config (or app.config)
There should be a one liner in the xml that has "default instance" or
something like that in there.
Database db = DatabaseFactory.CreateDatabase("myInstance");
this gets a specific instance. this should be the name of the connection
string.
The EntLib developers decided to piggy back off the new 2.0 connection
string stuff, instead of trying to reproduce (or replace it).
I actually prefer the .LoadDataSet method
//start code
db.LoadDataSet(dbCommand , productsDataSet , new string[]{
"table1", "table2" });
productsDataSet;
because I specifically name the tables. if you have a strong typed dataset,
then the tablenames have to match your strong tablenames of course.

- Show quoted text -

Certainly, I believe there's an overload which takes a string and that
allows you to have multiple entries in the config for different
databases.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top