pachecosita
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.Conne ctionStrin gs("test") .ToString( )
sample web config in VS 2008 is given below
<configuration>
<connectionStrings>
<add name="test" connectionString="my connection string"/>
</connectionStrings>
<system.diagnostics>
...
1. Add Reference to a dll, "System.Configuration"
2. Use below code to get the connection string value.
ConfigurationManager.Conne
sample web config in VS 2008 is given below
<configuration>
<connectionStrings>
<add name="test" connectionString="my connection string"/>
</connectionStrings>
<system.diagnostics>
...
ASKER
You rock!
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.