• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1335
  • 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" ?>
<configuration>
 
      <connectionStrings>
        <add name="theDB" connectionString="\.SQLExpress"
            providerName="System.Data.SqlClient" />
      </connectionStrings>
       
</configuration>

console app
 Dim oConn As New SqlConnection(My.Settings.theDB)
0
doramail05
Asked:
doramail05
  • 2
1 Solution
 
rgn2121Commented:
Instead of My.Settings.theDB, try System.Configuration.ConfigurationManager.ConnectionStrings("theDB").ConnectionString
0
 
rgn2121Commented:
You will have to add a reference to System.Configuration and then you can use an Imports statement to shorten that down a little...
0
 
sachinpatil10dCommented:
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
0
 
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.
0
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

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

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