Solved

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

Posted on 2009-04-08
4
1,416 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
Comment Utility
You need to set a reference to System.Configuration.dll
0
 
LVL 12

Expert Comment

by:rgn2121
Comment Utility
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
Comment Utility
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
Comment Utility
You rock!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
This video teaches viewers about errors in exception handling.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now