Solved

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

Posted on 2009-04-08
4
1,420 Views
Last Modified: 2012-05-06
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
0
Comment
Question by:pachecosita
4 Comments
 
LVL 10

Accepted Solution

by:
Chad Smith earned 500 total points
ID: 24103576
You need to set a reference to System.Configuration.dll
0
 
LVL 12

Expert Comment

by:rgn2121
ID: 24103649
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.
 
0
 
LVL 25

Expert Comment

by:apeter
ID: 24104770
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>
...
0
 

Author Closing Comment

by:pachecosita
ID: 31568347
You rock!
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

830 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