Solved

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

Posted on 2009-04-08
4
1,423 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
[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
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

636 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