how does it know which connection string to use?

Data Access Application Blocks Forum

how does it know which connection string to use?

Postby doph on Thu Jan 17, 2008 1:57 pm

I am new to EasyObjects and I used the getting started manuals to use MyGeneration to generate stored procs, abstruct and concrete classes. It did pretty well and I tried a little test with it:

Restaurant r = new Restaurant();
r.AddNew();
r.ID = Guid.NewGuid();
r.Name = TextBox1.Text;
r.Catering = CheckBoxList1.Items[0].Selected;
r.Valet = CheckBoxList1.Items[1].Selected;
r.Delivery = CheckBoxList1.Items[2].Selected;
r.Save();

it failes with null ref ex on Database db = GetDatabase();

no wonder - it does not know which database to connect to - there is a connection string in web.config but how do I tell the generated code to use it?

Many thanks and sorry for a dumb question.
doph
Lurker
 
Posts: 2
Joined: Thu Jan 17, 2008 1:50 pm

Postby mgnoonan on Thu Jan 17, 2008 6:02 pm

Hi doph,

That's actually an Enterprise Library thing. If you open your web.config or app.config file in the EL Configuration Tool and click on the Data Access Application Block, one of the node properties is DefaultDatabase. Set this to the name of the connection string you want to use as the default.

As an alternative, you can always specify which connection string you want in code:

Code: Select all
Restaurant r = new Restaurant();
r.DatabaseInstanceName = \"LocalSqlServer\";
r.AddNew();
...
etc.
Matt Noonan
EasyObjects.NET - The O/RM for the Enterprise Library
http://www.easyobjects.net
User avatar
mgnoonan
Expert
 
Posts: 1019
Joined: Tue Sep 14, 2004 3:17 am
Location: Springboro, OH

Postby doph on Thu Jan 17, 2008 6:40 pm

Thanks a lot, mgnoonan, this helped!
doph
Lurker
 
Posts: 2
Joined: Thu Jan 17, 2008 1:50 pm


Return to EasyObjects.NET (Microsoft Enterprise Library)

Who is online

Users browsing this forum: No registered users and 2 guests

cron