nsForum logo

Welcome Guest ( Log In )

 
Reply to this topicStart new topic
> Reading Connectionstrings From Web.config
UncleMoki
post Sep 29 2009, 02:29 PM
Post #1





Group: Verified NS Member
Posts: 4
Joined: 28-September 09
Member No.: 5,316



NOOB...HELP!!! Trying to read a connection string from web.config. I have a simple page with a text-box and button. On Click, the button runs code to retrieve the connection string from web.config. The app works fine locally. For reference, I used the VB example from MSDN:
http://msdn.microsoft.com/en-us/library/ms178411(VS.80).aspx

I've uploaded web.config and Default.aspx to the root directory of my site...and the dll to a bin folder that I created in the root. The page displays fine. However, when I click the button, the followig line fails:
CODE
rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("")

The error is:
CODE
Request for the permission of type 'System.Security.Permissions.RegistryPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Note: For giggles, I added a <trust>...</trust> tag to my web.config as follows and now I can duplicate the error locally:
CODE
   <trust
       level="Medium"
       originUrl=""
       processRequestInApplicationTrust="true"
    />

To be honest, I'm not really following what any of this means. I think understand the general idea of trust, but I can't say I understand what is really happening. If I were to guess, I'd say that the line of code above requires FULL TRUST, so running the app with anything less causes the line to fail. But if that were true, then that would mean that web apps can't read connection strings from web.config unless your app runs in full trust...and that doesn't sound right.

Any adivce?
Go to the top of the page
 
+Quote Post
UncleMoki
post Sep 29 2009, 02:52 PM
Post #2





Group: Verified NS Member
Posts: 4
Joined: 28-September 09
Member No.: 5,316



Ok, so I scrapped the MSDN code sample I mentioned earlier and used the following instead. Problem solved.
CODE
Dim connStr As String = ConfigurationManager.ConnectionStrings("MyDBConn").ConnectionString

Now the REAL question would be .... WHY did the MSDN article suggested the, "OpenWebConfiguration" method if it only works in a full trust environment?
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
Tags
No Tag inserted yet

1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version    Network Solutions © 2009 Time is now: 21st November 2009 - 08:04 PM
Domain Names | Web Hosting | Web Design | Shopping Cart Software | Online Marketing | SSL Certificates