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 get connection string from app.config

about get connection string from app.config

Scheduled Pinned Locked Moved C#
help
7 Posts 3 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.
  • P Offline
    P Offline
    papyrus_lei
    wrote on last edited by
    #1

    two projects,BusinessLayer and DataAcessLayer. DataAcessLayer includes CustomerDB.cs, App.config. App.config is like this: CustomerDB class has method GetCustomers public DataTable GetCustomers() { string ConnectionString = ConfigurationSettings.AppSettings ["ConncetionString"]; ............ } when i call GetCustomers() in BusinessLayer, the ConncetionString is always null. but i did have a successful try before. please help me,thanks. -- modified at 23:06 Tuesday 27th September, 2005

    T G 2 Replies Last reply
    0
    • P papyrus_lei

      two projects,BusinessLayer and DataAcessLayer. DataAcessLayer includes CustomerDB.cs, App.config. App.config is like this: CustomerDB class has method GetCustomers public DataTable GetCustomers() { string ConnectionString = ConfigurationSettings.AppSettings ["ConncetionString"]; ............ } when i call GetCustomers() in BusinessLayer, the ConncetionString is always null. but i did have a successful try before. please help me,thanks. -- modified at 23:06 Tuesday 27th September, 2005

      T Offline
      T Offline
      therealmccoy
      wrote on last edited by
      #2

      just a WAG... You might want to try including an \ before each of the quotes in your connection string. There also seems to be a missing quote after Server Name =" If the value needs to be null I would try: Server Name =\"\" Provider might also need to use \" instead of ' but alas it's just a WAG and I'm sure someone else will point me (or you) the right way Let me know if it works. www.lovethosetrains.com

      P G 2 Replies Last reply
      0
      • T therealmccoy

        just a WAG... You might want to try including an \ before each of the quotes in your connection string. There also seems to be a missing quote after Server Name =" If the value needs to be null I would try: Server Name =\"\" Provider might also need to use \" instead of ' but alas it's just a WAG and I'm sure someone else will point me (or you) the right way Let me know if it works. www.lovethosetrains.com

        P Offline
        P Offline
        papyrus_lei
        wrote on last edited by
        #3

        i delete some detail of the connection string because here is messageboards. i can get right value of connection string if i call GetCustomers() in project DataAccessLayer. but if i call GetCustomers() in BusinessLayer the conncetion string is always null. thanks anyway.

        1 Reply Last reply
        0
        • T therealmccoy

          just a WAG... You might want to try including an \ before each of the quotes in your connection string. There also seems to be a missing quote after Server Name =" If the value needs to be null I would try: Server Name =\"\" Provider might also need to use \" instead of ' but alas it's just a WAG and I'm sure someone else will point me (or you) the right way Let me know if it works. www.lovethosetrains.com

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          Using \ as escape character does not work in xml. If you check closely, there is no quoute after server name, it is two apostrophes. --- b { font-weight: normal; }

          1 Reply Last reply
          0
          • P papyrus_lei

            two projects,BusinessLayer and DataAcessLayer. DataAcessLayer includes CustomerDB.cs, App.config. App.config is like this: CustomerDB class has method GetCustomers public DataTable GetCustomers() { string ConnectionString = ConfigurationSettings.AppSettings ["ConncetionString"]; ............ } when i call GetCustomers() in BusinessLayer, the ConncetionString is always null. but i did have a successful try before. please help me,thanks. -- modified at 23:06 Tuesday 27th September, 2005

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            How are the projects related? Have you referenced the business layer in the web project? --- b { font-weight: normal; }

            P 1 Reply Last reply
            0
            • G Guffa

              How are the projects related? Have you referenced the business layer in the web project? --- b { font-weight: normal; }

              P Offline
              P Offline
              papyrus_lei
              wrote on last edited by
              #6

              there were two project BLL and DAL, BLL use DAL to complete some CRUD jobs. i have referenced DAL in BLL. thanks ^_^

              T 1 Reply Last reply
              0
              • P papyrus_lei

                there were two project BLL and DAL, BLL use DAL to complete some CRUD jobs. i have referenced DAL in BLL. thanks ^_^

                T Offline
                T Offline
                therealmccoy
                wrote on last edited by
                #7

                Ok I'll byte again... by chance are u creating a new instance of your DAL in BLL and then not reading the app.config? If the variable holding your connection string is not static then it would be null when you created a new instance of DAL. You could try declaring your connection string variable in DAL as static (might not be good practice) and see what you get. I was thinking maybe your method only returns a (GET) value and does not actually go out and read the app.config. :+) www.lovethosetrains.com -- modified at 22:20 Wednesday 28th September, 2005

                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