Link to home
Start Free TrialLog in
Avatar of doramail05
doramail05Flag for Malaysia

asked on

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)
Avatar of rgn2121
rgn2121
Flag of United States of America image

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...
ASKER CERTIFIED SOLUTION
Avatar of sachinpatil10d
sachinpatil10d
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.