'System.Configuration' is a namespace and cannot be used as an expression

I'm trying to form this right for my .NET 2.0 app

 Dim Conn As SqlConnection = New SqlConnection(System.Configuration!System.Configuration.ConfigurationManager.AppSettings("MYConn"))

Error      3      'System.Configuration' is a namespace and cannot be used as an expression
LVL 1
dba123Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DBAduck - Ben MillerPrincipal ConsultantCommented:
Shouldn't it be:

Dim Conn As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("MYConn"))

I am not sure where you got the "System.Configuration!" in your statement, but that is what it is complaining about.

Ben Miller
dba123Author Commented:
System.Configuration - asp.net 1.1
dba123Author Commented:

System.Configuration.ConfigurationManager.AppSettings

Error      2      'ConfigurationManager' is not a member of 'Configuration'.
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

DBAduck - Ben MillerPrincipal ConsultantCommented:
Oh, my point was that you had it in there 2 times.

To reference AppSettings you could either put an Imports statement in the top of the code for System.Configuration or reference it with full namespace like I put in my other comment.

The post originally in the question had System.Configuration!System.Configuration which is a duplicate and the ! indicates an Expression not a namespace.

HTH.
Ben Miller
dba123Author Commented:
it's not liking ConfigurationManager is my point...
dba123Author Commented:
I have this System.Configuration.ConfigurationManager.AppSettings

but it is not liking ConfigurationManager as in my error states.  This is a VB.NET console application. I've placed the connection string in app.config
DBAduck - Ben MillerPrincipal ConsultantCommented:
Oh, man.

Sorry.  If it is 1.1 then it should look like this:

System.Configuration.ConfigurationSettings.AppSettings("MyConn")

Sorry for the misunderstanding.
dba123Author Commented:
this is ASP.NET 2.0.  I'm trying to do what I normally do in my ASP.NET apps which is form my connection string and reference it from my .config file.  THIS however is a VB.NET console app in which I"m trying to do the same thing.  I have created an App.config file, and in it put the same type of connection string as I have done in my ASP.NET apps...unfortunately it doesn't seem to work.

Let me restate the entire issue.

vironment:
Using VS 2005
Coding in .NET 2.0
Problem:
If I'm creating let's say a VB.NET console application, how do I tie in the connection string properly right down to syntax for .NET 2.0 if I have to work with portions in my Database such as writing files to a specific directory using System.IO and doing a lookup vie a lookup function I am creating to look up values in my SQL Table?  With ASP.NET you define your connection string in web.config but what about a console app?
I tried to add a new app.config to my console app.  In it have this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.diagnostics>
        <sources>
            <!-- This section defines the logging configuration for My.Application.Log -->
            <source name="DefaultSource" switchName="DefaultSwitch">
                <listeners>
                    <add name="FileLog"/>
                    <!-- Uncomment the below section to write to the Application Event Log -->
                    <!--<add name="EventLog"/>-->
                </listeners>
            </source>
        </sources>
        <switches>
            <add name="DefaultSwitch" value="Information" />
        </switches>
        <sharedListeners>
            <add name="FileLog"
                 type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
                 initializeData="FileLogWriter"/>
            <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
            <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
        </sharedListeners>
    </system.diagnostics>

  <connectionStrings>
    <add name="MYConn"
         connectionString="Data Source=myserver;Initial Catalog=mydb; integrated security=SSPI;persist security info=False; Trusted_Connection=Yes"
         providerName="System.Data.SqlClient" />
  </connectionStrings>
 
</configuration>
In my console.vb code, in one of my functions I have this:
Dim objConn As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("MYConn"))
I get the error in my .vb code: Error 2 'ConfigurationManager' is not a member of 'Configuration'.

dba123Author Commented:
Environment:
-----------------
Using VS 2005
Coding in .NET 2.0

Problem:
----------
If I'm creating let's say a VB.NET console application, how do I tie in the connection string properly right down to syntax for .NET 2.0 if I have to work with portions in my Database such as writing files to a specific directory using System.IO and doing a lookup vie a lookup function I am creating to look up values in my SQL Table?  With ASP.NET you define your connection string in web.config but what about a console app?
I tried to add a new app.config to my console app.  In it have this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.diagnostics>
        <sources>
            <!-- This section defines the logging configuration for My.Application.Log -->
            <source name="DefaultSource" switchName="DefaultSwitch">
                <listeners>
                    <add name="FileLog"/>
                    <!-- Uncomment the below section to write to the Application Event Log -->
                    <!--<add name="EventLog"/>-->
                </listeners>
            </source>
        </sources>
        <switches>
            <add name="DefaultSwitch" value="Information" />
        </switches>
        <sharedListeners>
            <add name="FileLog"
                 type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
                 initializeData="FileLogWriter"/>
            <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
            <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
        </sharedListeners>
    </system.diagnostics>

  <connectionStrings>
    <add name="MYConn"
         connectionString="Data Source=myserver;Initial Catalog=mydb; integrated security=SSPI;persist security info=False; Trusted_Connection=Yes"
         providerName="System.Data.SqlClient" />
  </connectionStrings>
 
</configuration>


In my console.vb code, in one of my functions I have this:
Dim objConn As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("MYConn"))
I get the error in my .vb code: Error 2 'ConfigurationManager' is not a member of 'Configuration'.

dba123Author Commented:
I'm going to start using my template when posting, I think it makes the issue more clear....tell me if the template helps.
DBAduck - Ben MillerPrincipal ConsultantCommented:
OK, if you are using 2.0 and VB.NET and a Console app.

Here goes.

the first thing is that you need to set a Reference to System.Configuration because you do not get this one for free, especially in a Console App.

So right click on the project in VS and choose Add Reference.  Select System.Configuraiton and it will add the reference to your project.
Then put a statement at the top of your Module for the Console App:

Imports System.Configuration

Now you can use the following line of code to get your connection string.

Dim objConn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("MyConn").ConnectionString)

Ben Miller

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dba123Author Commented:
dba123Author Commented:
Thank God, literally!
dba123Author Commented:
this was driving me batty.  I had the namespace imported....ahh but it's so picky in 2.0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.