Connecting Tech Pros Worldwide Forums | Help | Site Map

Question on Data Access Application Block (DAAB)

stephen
Guest
 
Posts: n/a
#1: Jul 24 '06
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").Exec uteDataSet(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(Co mmandType.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



Murtaza
Guest
 
Posts: n/a
#2: Jul 26 '06

re: Question on Data Access Application Block (DAAB)


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.

"stephen" wrote:
Quote:
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").Exec uteDataSet(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(Co mmandType.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
>
>
>
snitsrevenge@gmail.com
Guest
 
Posts: n/a
#3: Aug 5 '06

re: Question on Data Access Application Block (DAAB)


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.

Closed Thread