Solved

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

Posted on 2012-04-05
4
1,229 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The canonical version of this article is on my web site here: http://iconoun.com/articles/collisions/ A companion presentation is available here: http://iconoun.com/articles/collisions/Unicode_Presentation.pdf
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 …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

895 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

17 Experts available now in Live!

Get 1:1 Help Now