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. Web Development
  3. ASP.NET
  4. Unable to access connection string from app config

Unable to access connection string from app config

Scheduled Pinned Locked Moved ASP.NET
questionworkspace
9 Posts 4 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.
  • J Offline
    J Offline
    John ph
    wrote on last edited by
    #1

    I have been trying for hours now. but unable to access the connection strng from app config file. 1. Application has reference to System.Configuration.dll 2. App Config file has the connectionString still the following code returns nothing.

    Private Shared Function GetConnectionString( _
    ByVal name As String) As String

        Dim returnValue As String = Nothing
    
       Dim settings As ConnectionStringSettings = \_
           ConfigurationManager.ConnectionStrings(name)
    
        If Not settings Is Nothing Then
            returnValue = settings.ConnectionString
        End If
    
        Return returnValue
    

    End Function

    can any one guess what's going wrong?

    - Regards -
       J O N


    A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers


    S N 2 Replies Last reply
    0
    • J John ph

      I have been trying for hours now. but unable to access the connection strng from app config file. 1. Application has reference to System.Configuration.dll 2. App Config file has the connectionString still the following code returns nothing.

      Private Shared Function GetConnectionString( _
      ByVal name As String) As String

          Dim returnValue As String = Nothing
      
         Dim settings As ConnectionStringSettings = \_
             ConfigurationManager.ConnectionStrings(name)
      
          If Not settings Is Nothing Then
              returnValue = settings.ConnectionString
          End If
      
          Return returnValue
      

      End Function

      can any one guess what's going wrong?

      - Regards -
         J O N


      A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers


      S Offline
      S Offline
      SeMartens
      wrote on last edited by
      #2

      Hi, just a wild guess, but I think you have to use the connectionstring within the web.config file. ASP.NET projects get their application settings from there. Must look like this:

      <connectionStrings>
      <add name="MyConnectionString" connectionString="here it goes" />
      </connectionStrings>

      Regards Sebastian

      J 1 Reply Last reply
      0
      • S SeMartens

        Hi, just a wild guess, but I think you have to use the connectionstring within the web.config file. ASP.NET projects get their application settings from there. Must look like this:

        <connectionStrings>
        <add name="MyConnectionString" connectionString="here it goes" />
        </connectionStrings>

        Regards Sebastian

        J Offline
        J Offline
        John ph
        wrote on last edited by
        #3

        it's a seperate library project for DataAccess (DAL). Added a app config file. I'm trying to take the connection string from there instead of passing it through the presentation, BAL... this is what I have in app config file

        <connectionStrings>
        <add name="Name" providerName="Provider Name" connectionString="Connection String" />
        </connectionStrings>

        - Regards -
           J O N


        A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers


        S 1 Reply Last reply
        0
        • J John ph

          it's a seperate library project for DataAccess (DAL). Added a app config file. I'm trying to take the connection string from there instead of passing it through the presentation, BAL... this is what I have in app config file

          <connectionStrings>
          <add name="Name" providerName="Provider Name" connectionString="Connection String" />
          </connectionStrings>

          - Regards -
             J O N


          A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers


          S Offline
          S Offline
          SeMartens
          wrote on last edited by
          #4

          Hmm, don't know if this works. As far as i know the config is loaded by the app, and in this case this is a web-app, expecting a web.config. But maybe you can load the app.config with the configuration manager manually? Regards Sebastian

          1 Reply Last reply
          0
          • J John ph

            I have been trying for hours now. but unable to access the connection strng from app config file. 1. Application has reference to System.Configuration.dll 2. App Config file has the connectionString still the following code returns nothing.

            Private Shared Function GetConnectionString( _
            ByVal name As String) As String

                Dim returnValue As String = Nothing
            
               Dim settings As ConnectionStringSettings = \_
                   ConfigurationManager.ConnectionStrings(name)
            
                If Not settings Is Nothing Then
                    returnValue = settings.ConnectionString
                End If
            
                Return returnValue
            

            End Function

            can any one guess what's going wrong?

            - Regards -
               J O N


            A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers


            N Offline
            N Offline
            N a v a n e e t h
            wrote on last edited by
            #5

            Have you stepped into the code? Are you getting ConfigurationManager.ConnectionStrings as NOTHING?

            Navaneeth How to use google | Ask smart questions

            J 1 Reply Last reply
            0
            • N N a v a n e e t h

              Have you stepped into the code? Are you getting ConfigurationManager.ConnectionStrings as NOTHING?

              Navaneeth How to use google | Ask smart questions

              J Offline
              J Offline
              John ph
              wrote on last edited by
              #6

              yes, ConfigurationManager.ConnectionStrings returns NOTHING. but i have a valid connection string with a NAME and PROVIDER NAME in the app config file.

              - Regards -
                 J O N


              A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers


              J 1 Reply Last reply
              0
              • J John ph

                yes, ConfigurationManager.ConnectionStrings returns NOTHING. but i have a valid connection string with a NAME and PROVIDER NAME in the app config file.

                - Regards -
                   J O N


                A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers


                J Offline
                J Offline
                Jaffer Mumtaz
                wrote on last edited by
                #7

                Hi, Try using the following

                System.Configuration.ConfigurationSettings.AppSettings("ConnectionString").ToString()

                and in app.config

                <appSettings>
                <add key="ConnectionString" value="Data Source=MyData;Initial Catalog=Data;Integrated Security=False;User id=abcd;Password=1234;"/>
                </appSettings>

                J 1 Reply Last reply
                0
                • J Jaffer Mumtaz

                  Hi, Try using the following

                  System.Configuration.ConfigurationSettings.AppSettings("ConnectionString").ToString()

                  and in app.config

                  <appSettings>
                  <add key="ConnectionString" value="Data Source=MyData;Initial Catalog=Data;Integrated Security=False;User id=abcd;Password=1234;"/>
                  </appSettings>

                  J Offline
                  J Offline
                  John ph
                  wrote on last edited by
                  #8

                  ConfigurationSettings.AppSettings("DBConnectString") returns NOTHING

                  - Regards -
                     J O N


                  A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers


                  J 1 Reply Last reply
                  0
                  • J John ph

                    ConfigurationSettings.AppSettings("DBConnectString") returns NOTHING

                    - Regards -
                       J O N


                    A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers


                    J Offline
                    J Offline
                    Jaffer Mumtaz
                    wrote on last edited by
                    #9

                    Paste the code of your app.config and the code which you are calling to access it

                    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