Solved

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

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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