Solved

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

Posted on 2012-04-05
4
1,236 Views
Last Modified: 2012-04-05
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
Comment
Question by:doramail05
  • 2
4 Comments
 
LVL 12

Expert Comment

by:rgn2121
ID: 37810327
Instead of My.Settings.theDB, try System.Configuration.ConfigurationManager.ConnectionStrings("theDB").ConnectionString
0
 
LVL 12

Expert Comment

by:rgn2121
ID: 37810329
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
 
LVL 9

Accepted Solution

by:
sachinpatil10d earned 500 total points
ID: 37810531
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
 
LVL 40
ID: 37814359
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

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

831 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