Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. About SqlConnection String in App.config file

About SqlConnection String in App.config file

Scheduled Pinned Locked Moved C#
helpcsharpquestionlearningworkspace
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mwith
    wrote on last edited by
    #1

    :confused::((Hi sir, I wrote a app.config as follows I called that connection string like this, SqlConnection cn; sConn = System.Configuration.ConfigurationManager.AppSettings("dbconnection"); cn = new SqlConnection(sConn); cn.Open(); then it is an error : The type or namespace name 'ConfigurationManager' does not exist in the class or namespace 'System.Configuration' (are you missing an assembly reference?) I am a beginner for c# can you help me? thank you

    E J C 3 Replies Last reply
    0
    • M mwith

      :confused::((Hi sir, I wrote a app.config as follows I called that connection string like this, SqlConnection cn; sConn = System.Configuration.ConfigurationManager.AppSettings("dbconnection"); cn = new SqlConnection(sConn); cn.Open(); then it is an error : The type or namespace name 'ConfigurationManager' does not exist in the class or namespace 'System.Configuration' (are you missing an assembly reference?) I am a beginner for c# can you help me? thank you

      E Offline
      E Offline
      Eduard Keilholz
      wrote on last edited by
      #2

      Collapse your project in the Solution Explorer window and right click 'References' and choose 'Add Reference'. A popup window appears, on the .NET tab, choose System.Configuration and press the OK button. Try rebuilding your project ;-)

      - - - --[ i love it when a plan comes together ]-- - - -

      M 1 Reply Last reply
      0
      • M mwith

        :confused::((Hi sir, I wrote a app.config as follows I called that connection string like this, SqlConnection cn; sConn = System.Configuration.ConfigurationManager.AppSettings("dbconnection"); cn = new SqlConnection(sConn); cn.Open(); then it is an error : The type or namespace name 'ConfigurationManager' does not exist in the class or namespace 'System.Configuration' (are you missing an assembly reference?) I am a beginner for c# can you help me? thank you

        J Offline
        J Offline
        Jasmine2501
        wrote on last edited by
        #3

        mwith wrote:

        Hi sirs and madams,

        (fixed that for ya) You need to have: using System.Configuration; at the top of your code file. You might also need to explicitly add the reference to the System.Configuration assembly to your project. (Right-click on 'References' in the solution explorer, and click 'Add Reference...', then select the System.Configuration assembly, which is under the .Net tab in the window that pops up, and add that assembly to your project.) You will need to add a name attribute to your config file entry, or the app can't tell what you mean by 'dbconnection'. I do it like this: <appSettings> <add key="dbconnection" value="myconnectionstringwhateveritis"/> </appSettings> Also, I hope you didn't just give us all your SA login info. You need to change that right away if you did.

        "Quality Software since 1983!"
        http://www.smoothjazzy.com/ - see the "Programming" section for (freeware) JazzySiteMaps, a simple application to generate .Net and Google-style sitemaps!

        R E 2 Replies Last reply
        0
        • E Eduard Keilholz

          Collapse your project in the Solution Explorer window and right click 'References' and choose 'Add Reference'. A popup window appears, on the .NET tab, choose System.Configuration and press the OK button. Try rebuilding your project ;-)

          - - - --[ i love it when a plan comes together ]-- - - -

          M Offline
          M Offline
          mwith
          wrote on last edited by
          #4

          Hi I tried that, but there is no just System.Configuration. it has System.Configuration.install.dll I add that. but same error is coming. thanks

          J 1 Reply Last reply
          0
          • M mwith

            Hi I tried that, but there is no just System.Configuration. it has System.Configuration.install.dll I add that. but same error is coming. thanks

            J Offline
            J Offline
            Jasmine2501
            wrote on last edited by
            #5

            That means you already added it, and you just need the Using statement I mentioned.

            "Quality Software since 1983!"
            http://www.smoothjazzy.com/ - see the "Programming" section for (freeware) JazzySiteMaps, a simple application to generate .Net and Google-style sitemaps!

            1 Reply Last reply
            0
            • J Jasmine2501

              mwith wrote:

              Hi sirs and madams,

              (fixed that for ya) You need to have: using System.Configuration; at the top of your code file. You might also need to explicitly add the reference to the System.Configuration assembly to your project. (Right-click on 'References' in the solution explorer, and click 'Add Reference...', then select the System.Configuration assembly, which is under the .Net tab in the window that pops up, and add that assembly to your project.) You will need to add a name attribute to your config file entry, or the app can't tell what you mean by 'dbconnection'. I do it like this: <appSettings> <add key="dbconnection" value="myconnectionstringwhateveritis"/> </appSettings> Also, I hope you didn't just give us all your SA login info. You need to change that right away if you did.

              "Quality Software since 1983!"
              http://www.smoothjazzy.com/ - see the "Programming" section for (freeware) JazzySiteMaps, a simple application to generate .Net and Google-style sitemaps!

              R Offline
              R Offline
              Russell Jones
              wrote on last edited by
              #6

              With a password like that he'd want to change it even if he hadn't posted it on the internet. I'm assuming that he's changed it to sa like i would change mine to pwd if posting stuff on a forum. Reminds me of a place i worked where the head of IT was one of the owners of the company. While searching for some info about recordsets on usenet i saw a post of his from 5 years before. I duly went to have a look and found a username and password URL and port in his example code. I then discovered that not only had he not changed the password for this account but it was on a server that was still exposed to the internet and had domain admin permissions on our internal network. When i asked him about it, he said "That account, oh we haven't used it for ages, why do you ask". sorry for the OT, Russ

              1 Reply Last reply
              0
              • J Jasmine2501

                mwith wrote:

                Hi sirs and madams,

                (fixed that for ya) You need to have: using System.Configuration; at the top of your code file. You might also need to explicitly add the reference to the System.Configuration assembly to your project. (Right-click on 'References' in the solution explorer, and click 'Add Reference...', then select the System.Configuration assembly, which is under the .Net tab in the window that pops up, and add that assembly to your project.) You will need to add a name attribute to your config file entry, or the app can't tell what you mean by 'dbconnection'. I do it like this: <appSettings> <add key="dbconnection" value="myconnectionstringwhateveritis"/> </appSettings> Also, I hope you didn't just give us all your SA login info. You need to change that right away if you did.

                "Quality Software since 1983!"
                http://www.smoothjazzy.com/ - see the "Programming" section for (freeware) JazzySiteMaps, a simple application to generate .Net and Google-style sitemaps!

                E Offline
                E Offline
                Eduard Keilholz
                wrote on last edited by
                #7

                That's not really true, it would be neat though, but as you can see in his code, het uses the entire namespace in his code : System.Configuration.ConfigurationManager.AppSettings["name"] which does not require a 'using' statement, but again... it would be neat...

                - - - --[ i love it when a plan comes together ]-- - - -

                J 1 Reply Last reply
                0
                • E Eduard Keilholz

                  That's not really true, it would be neat though, but as you can see in his code, het uses the entire namespace in his code : System.Configuration.ConfigurationManager.AppSettings["name"] which does not require a 'using' statement, but again... it would be neat...

                  - - - --[ i love it when a plan comes together ]-- - - -

                  J Offline
                  J Offline
                  Jasmine2501
                  wrote on last edited by
                  #8

                  Yeah you're right... I totally missed that. I think he's using .Net 1.1, but I can't remember what the difference was. With a .Net 2.0 project, it should be working if the assembly is added like he said.

                  "Quality Software since 1983!"
                  http://www.smoothjazzy.com/ - see the "Programming" section for (freeware) JazzySiteMaps, a simple application to generate .Net and Google-style sitemaps!

                  E 1 Reply Last reply
                  0
                  • J Jasmine2501

                    Yeah you're right... I totally missed that. I think he's using .Net 1.1, but I can't remember what the difference was. With a .Net 2.0 project, it should be working if the assembly is added like he said.

                    "Quality Software since 1983!"
                    http://www.smoothjazzy.com/ - see the "Programming" section for (freeware) JazzySiteMaps, a simple application to generate .Net and Google-style sitemaps!

                    E Offline
                    E Offline
                    Eduard Keilholz
                    wrote on last edited by
                    #9

                    Erhm, you don't have the configurationmanager object there... The .NET 1.1 ols fashion way is System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"] (or ofcourse) using System.Configuration; and ConfigurationSettings.AppSettings["ConnectionString"]

                    - - - --[ i love it when a plan comes together ]-- - - -

                    1 Reply Last reply
                    0
                    • M mwith

                      :confused::((Hi sir, I wrote a app.config as follows I called that connection string like this, SqlConnection cn; sConn = System.Configuration.ConfigurationManager.AppSettings("dbconnection"); cn = new SqlConnection(sConn); cn.Open(); then it is an error : The type or namespace name 'ConfigurationManager' does not exist in the class or namespace 'System.Configuration' (are you missing an assembly reference?) I am a beginner for c# can you help me? thank you

                      C Offline
                      C Offline
                      Colin Angus Mackay
                      wrote on last edited by
                      #10

                      What version of visual studio / .NET Framework are you using. The code you have will only work in .NET 2.0 (Visual Studio 2005). Also, replace the () with [] after AppSettings because once you've fixed this error your going to get another.


                      Upcoming Scottish Developers events: * We are starting a series of events in Glasgow in 2007. Are you interested in a particular subject, or as a speaker? * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog | Photos

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups