Question on Data Access Application Block (DAAB)

S

stephen

Hi,

I have Question on DAAB.
I created 2 connection parameters one for Development box and another For
Test box, when I tried to access them using this piece of code, I get an
error

Here's what I did:
in the dataConfiguration.config:
<instances>
<instance name="Database Instance" type="Sql Server"
connectionString="Development" />
<instance name="Database Instance" type="Sql Server"
connectionString="Test" />
</instances>
<connectionStrings>
<connectionString name="Development">
<parameters>
---Some parameters here---
</parameters>
</connectionString>
<connectionString name="Test">
<parameters>
---Some parameters here---
</parameters>
</connectionString>
</connectionStrings>

In the Code:
I tried this
Dim ds As DataSet =
DatabaseFactory.CreateDatabase("Development").ExecuteDataSet(CommandType.Text,
_
"SELECT * FROM Categories ORDER BY CategoryName")

It gave me an error....


but when I changed it to this
Dim ds As DataSet =
DatabaseFactory.CreateDatabase().ExecuteDataSet(CommandType.Text, _
"SELECT * FROM Categories ORDER BY CategoryName")

it worked fine...
I understand it takes the default value from the dataConfiguration.config
file but everytime i switch from Dev to Test i have to change the
connectionString in instance name to point appropriately...

can you please tell me how to avoid this?


Thanks,
Stephen
 
G

Guest

Well sir i m afraid you have to do this way simply because u ve inserted 2
keys with similar name so .NET will return the fiirst value it will find.
Other wise you have to provide name. Otherwise bydefault it will always take
the Dev string.
 
S

snitsrevenge

I'm replying to this post because its the most recent applicable area I
can find. I searched forever to find vb.net style code to hit a stored
proc using the DAAB for the sole purpose of looping thru it. Here is
what worked for me. I'm sure something is screwed up with it, but it
worked. So feel free to comment on how to release/dispose, do
differently, etc.:
------
Dim db As Database = DatabaseFactory.CreateDatabase("DATABASE
CONNECTION NAME STRING DEFINED IN WEB.CONFIG UNDER
<connectionStrings>")

Dim dr As SqlDataReader = db.ExecuteReader("PROC NAME")

While dr.Read
Response.Write(dr.GetString(1))
End While

dr.Close()
dr = Nothing

-------------

Maybe my Google searching capabilities have turned into shite, but I
could not find simple examples of this anywhere.

Bob.
 

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

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top