• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1307
  • Last Modified:

Connection String in app.config for console app vb.net

While trying to connect to SQL with connectionstring in console app with app.config, saying that 'My.Settings.theDB' is not a member of Test.My.MySettings.

app.config<?xml version="1.0" encoding="utf-8" ?>
        <add name="theDB" connectionString="\.SQLExpress"
            providerName="System.Data.SqlClient" />

console app
 Dim oConn As New SqlConnection(My.Settings.theDB)
  • 2
1 Solution
Instead of My.Settings.theDB, try System.Configuration.ConfigurationManager.ConnectionStrings("theDB").ConnectionString
You will have to add a reference to System.Configuration and then you can use an Imports statement to shorten that down a little...
When App.Config is auto generated from project properties settings the we access My.Settings.Setting
App.Config is manually added we follow the rgn2121 solution
Jacques Bourgeois (James Burger)PresidentCommented:
To access an entry in the configuration file through My.Settings, you need to first define it manually in the Settings tab of the project's properties window, available at the bottom of the Project menu.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now