You can access the default database from the dataConfiguration section of your web.config and then assign the connection string to a SqlDataSource with an id of SqlDataSource1 using VB code such as:
<%@ Import Namespace="Microsoft.Practices.EnterpriseLibrary.Data.Configuration" %>
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dbSettings As DatabaseSettings = CType(ConfigurationManager.GetSection("dataConfiguration"), DatabaseSettings)
Dim defaultConnection As String = dbSettings.DefaultDatabase
SqlDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings(defaultConnection).ToString()
End Sub
It is even easier if you just want to check the value (as you requested):
Dim dbSettings As DatabaseSettings = CType(ConfigurationManager.GetSection("dataConfiguration"), DatabaseSettings)
Dim defaultConnection As String = dbSettings.DefaultDatabase
If (defaultConnection = "xxx") Then
' Do something
End If
Dexter007
Participant
1078 Points
180 Posts
defaultDatabase with dataConfiguration
Mar 25, 2008 05:55 AM|LINK
I m using DAAB...
in my web.config... I want as ...
<dataConfiguration defaultDatabase="OracleConnection"/>
It shows Error as "Unrecognized configuration section dataConfiguration"
whether i'm missing anything ?
----
j@y
Please remember to click “Mark as Answer” on the post(s) which helps you !
nKognito
Participant
1906 Points
376 Posts
Re: defaultDatabase with dataConfiguration
Mar 25, 2008 06:02 AM|LINK
First of all you need to create a dataConfiguration section:
Pay attention: use your provider (I used a MS enterprise library)
And then:
Dexter007
Participant
1078 Points
180 Posts
Re: defaultDatabase with dataConfiguration
Mar 25, 2008 06:45 AM|LINK
GR8........ Thanks a LOT....
----
j@y
Please remember to click “Mark as Answer” on the post(s) which helps you !
Dexter007
Participant
1078 Points
180 Posts
Re: defaultDatabase with dataConfiguration
Jul 23, 2008 12:44 PM|LINK
Hi nKognito,
How can i access defaultDatabase of dataConfiguration section in webcofig, from codebehind ?
Objective:
I want to check at runtime which is defaultDatabase .
Thanks.
----
j@y
Please remember to click “Mark as Answer” on the post(s) which helps you !
coolfriend
Member
6 Points
3 Posts
Re: defaultDatabase with dataConfiguration
Aug 18, 2009 10:38 AM|LINK
Thanks you very much this help me
architect-ma...
Member
2 Points
1 Post
Re: defaultDatabase with dataConfiguration
Dec 30, 2009 01:54 AM|LINK
You can access the default database from the dataConfiguration section of your web.config and then assign the connection string to a SqlDataSource with an id of SqlDataSource1 using VB code such as:
<%@ Import Namespace="Microsoft.Practices.EnterpriseLibrary.Data.Configuration" %> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim dbSettings As DatabaseSettings = CType(ConfigurationManager.GetSection("dataConfiguration"), DatabaseSettings) Dim defaultConnection As String = dbSettings.DefaultDatabase SqlDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings(defaultConnection).ToString() End SubIt is even easier if you just want to check the value (as you requested):
Dim dbSettings As DatabaseSettings = CType(ConfigurationManager.GetSection("dataConfiguration"), DatabaseSettings) Dim defaultConnection As String = dbSettings.DefaultDatabase If (defaultConnection = "xxx") Then ' Do something End Ifconnectionstring dataConfiguration SqlDataSource