Link to home
Start Free TrialLog in
Avatar of pachecosita
pachecositaFlag for United States of America

asked on

How do I access my connectionstring from app.config in VB.net 2008?

I am trying to read my connectionstring from app.config in VB.net 2008. I followed some instructions and this is how far I got:
1) typed this in my app.config:
<connectionstrings>
    <add key="localstring" value="data source=(local);initial catalog=tempdb;Integrated    Security=SSPI;"/>
 </connectionstrings>
2) declare outside my Data class:
Imports System.Configuration
3) then
in my function inside my Data class I typed:
Configuration.
and I did not get "configurationmanager" , it's not available
Do I need to setup something else in my program
please help
ASKER CERTIFIED SOLUTION
Avatar of Chad Smith
Chad Smith
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Did you add a reference to System.Configuration?
Also, I am not sure if this happens in 2008, but when I have done something similar in 2005 if I use the Imports System.Configuration I have issues.  I am not sure why that is, but in the past I have add the referecne and then typed the full namespace out to get to app settings.
 
Below are the steps you have to do.

1. Add Reference to a dll, "System.Configuration"
2. Use below code to get the connection string value.
             ConfigurationManager.ConnectionStrings("test").ToString()

sample web config in VS 2008 is given below

<configuration>
  <connectionStrings>
    <add name="test" connectionString="my connection string"/>
  </connectionStrings>
    <system.diagnostics>
...
Avatar of pachecosita

ASKER

You rock!