Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using the ConfigurationManager in a webcontrol.

Posted on 2008-10-06
23
Medium Priority
?
365 Views
Last Modified: 2012-06-27
I am using the following code to fetch all connectionstrings from web.config:

                    Dim ConnString As ConnectionStringSettings
                   
                    For Each ConnString In System.Configuration.ConfigurationManager.ConnectionStrings()
                        List.Add(ConnString.Name.ToString())
                    Next

This is working fine on codebehind of default.aspx, but as soon as I try to implement it in a webcontrol it does not fetch the connectionstrings anymore except for the 'standard' LocalSqlServer one.

Is this some security feature or should I address it differently from a webcontrol. Any insight would be great.

Cheers
0
Comment
Question by:Onthrax
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 7
  • 2
23 Comments
 
LVL 16

Expert Comment

by:ororiole
ID: 22656870
by a "webcontrol" do you mean a user control? that sould work fine. Or do you mean a custom web server control? You should probably post a snippet of your code for the control where you are using configmanager, we could help you better if you did.
0
 
LVL 13

Author Comment

by:Onthrax
ID: 22657239
I mean a custom web server control. I have done some further experimenting and it seems it is working fine at run time but not on design time. I'll try to elaborate.

I have created the following function to fetch all connectionstring names:
        Public Shared Function GetConnectionStringNames() As ArrayList

            Dim ConnString As ConnectionStringSettings
            Dim List As New ArrayList

            For Each ConnString In System.Configuration.ConfigurationManager.ConnectionStrings()
                List.Add(ConnString.Name.ToString())
            Next

            Return List

        End Function

When I import my control into the web page and call this function at run time the website displays the names perfectly.

However when I try to call this function at design time (visual studio) to incorporate at a property, only one name results back.

        <TypeConverter(GetType(EnumConverter))> _
        <Description("The connectionstring required to access the database.")> _
        <Category("ValidationMessages")> _
        Public Property ConnectionString() As String
            Get

                Throw New HttpException(GetConnectionStringNames.Count)    <== this returns 1, not 3

                Return CType(_ConnectionString, String)
            End Get
            Set(ByVal Value As String)
                _ConnectionString = Value
            End Set
        End Property

Any idea's?
0
 
LVL 13

Author Comment

by:Onthrax
ID: 22657265
Also why do you have a different picture (man icon) then everyone else?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 22658725
Is the web control in a DLL project, separate from the web site?
0
 
LVL 13

Author Comment

by:Onthrax
ID: 22658823
Yes, but located in the bin folder of the website.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22658900
The ConfigurationManager will not be looking for the web.config file, but a config file like dllassembly.dll.config.
0
 
LVL 13

Author Comment

by:Onthrax
ID: 22659099
That would mean the web.config file is read by the server and it's contents put in dllassembly.dll.config as at run time the correct number of connectionstrings are returned. Correct?

If so, I would have to read the web.config as XML and extract the connectionstrings node to fetch the names. Might be tricky as multiple web.config files can exist. Not impossible though.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22659128
No, not correct.  Your DLL assembly would need an App.config, which would be turned into that config file for the DLL.  The web.config file doesn't even come into play here.  I agree that you would have to read the web.config file yourself.  I do that for one of my DLL assemblies.
0
 
LVL 13

Author Comment

by:Onthrax
ID: 22659169
Then I don't get why this function will return the correct number of connection strings at run time but not at designtime..

       Public Shared Function GetConnectionStringNames() As ArrayList

            Dim ConnString As ConnectionStringSettings
            Dim List As New ArrayList

            For Each ConnString In System.Configuration.ConfigurationManager.ConnectionStrings()
                List.Add(ConnString.Name.ToString())
            Next

            Return List

        End Function
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 22659186
You win--that is the question of the day!!  I don't know :(
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22659198
Did you try a WebConfigurationManager?
0
 
LVL 13

Author Comment

by:Onthrax
ID: 22659225
w000t I win.. but this time I don't want to win lol.

I didn't know WebConfigurationManager is similar, I'll check it out and get back..
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22659248
I thought we were playing stump the expert *BIG GRIN*
0
 
LVL 13

Author Comment

by:Onthrax
ID: 22659353
Hehe.. well somehow it's comforting to know even an expert of status genius is yet unable to solve my problem :P

(still checking WebConfigurationManager though)
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22659398
It is a humble man that will admit that he doesn't know everything, despite what others might think.  *WINK*.
0
 
LVL 13

Author Comment

by:Onthrax
ID: 22659495
WebConfigurationManager turns out exactly the same.

Works at run time but does only return LocalSqlServer at design time. Very strange....
0
 
LVL 13

Author Comment

by:Onthrax
ID: 22676938
I am leaning toward accepting ID 22659186 as answer :P

I went along with reading web.config as XML which is working fine now.
Thanks for all your help m8 :) Highly appreciated!
0
 
LVL 16

Expert Comment

by:ororiole
ID: 22681330
>>Also why do you have a different picture (man icon) then everyone else?
If one of us can beat The Learned One in a head-to-head quiz, we get to wear the "leader" jacket. :)

j/k, its a new feature you can customize it in your profile.
0
 
LVL 13

Author Comment

by:Onthrax
ID: 22682158
Already noticed it today :P But thnx for letting me know :D
0
 
LVL 13

Author Comment

by:Onthrax
ID: 22948238
LOL @ recommendation :p



Thanks again for all your help m8. guess I forgot to close the question.. Cheers
0
 
LVL 13

Author Comment

by:Onthrax
ID: 22982766
Something went wrong here. I had accepted an answer and rewarded points to 3 posts....
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question