Solved

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

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

706 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

15 Experts available now in Live!

Get 1:1 Help Now