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. Chnaging connectionString and reloading it

Chnaging connectionString and reloading it

Scheduled Pinned Locked Moved C#
5 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.
  • M Offline
    M Offline
    mrkeivan
    wrote on last edited by
    #1

    Hey guys, I want to the following, load a specific connection string from app.config change it then re load it in run time. any suggestions THX

    T A 2 Replies Last reply
    0
    • M mrkeivan

      Hey guys, I want to the following, load a specific connection string from app.config change it then re load it in run time. any suggestions THX

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

      mrkeivan wrote:

      load a specific connection string from app.config change it then re load it in run time.

      Confusing little bit. Try this Connection Strings and Configuration Files [^]

      thatraja |Chennai|India|


      Brainbench certifications
      Down-votes are like kid's kisses don't reject it :-)
      Do what you want quickly because the Doomsday on 2012 :-)

      M 1 Reply Last reply
      0
      • T thatraja

        mrkeivan wrote:

        load a specific connection string from app.config change it then re load it in run time.

        Confusing little bit. Try this Connection Strings and Configuration Files [^]

        thatraja |Chennai|India|


        Brainbench certifications
        Down-votes are like kid's kisses don't reject it :-)
        Do what you want quickly because the Doomsday on 2012 :-)

        M Offline
        M Offline
        mrkeivan
        wrote on last edited by
        #3

        Hey, thanx for the quick reply, let me clarify what I posted earlier. I want to retrieve the connectionString I have, make a change to it (change the data source) and load it back in App.config. ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings[name]; // If found, return the connection string. if (settings != null) returnValue = settings.ConnectionString; return returnValue; something like this: returnValue = // my new connection string // now load it back and connect to database using the new string in runtime THX

        J 1 Reply Last reply
        0
        • M mrkeivan

          Hey, thanx for the quick reply, let me clarify what I posted earlier. I want to retrieve the connectionString I have, make a change to it (change the data source) and load it back in App.config. ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings[name]; // If found, return the connection string. if (settings != null) returnValue = settings.ConnectionString; return returnValue; something like this: returnValue = // my new connection string // now load it back and connect to database using the new string in runtime THX

          J Offline
          J Offline
          jschell
          wrote on last edited by
          #4

          That has nothing to do with "connection strings" though. Read up on using the app.config and Configuration class and the System.Configuration namespace. There is also a newer connection section that Microsoft added. Idea is similar. Also note that writing back to the App.config, as far as I am concerned, means it is no longer human maintainable. It will remove most formatting and all comments.

          1 Reply Last reply
          0
          • M mrkeivan

            Hey guys, I want to the following, load a specific connection string from app.config change it then re load it in run time. any suggestions THX

            A Offline
            A Offline
            alrosan
            wrote on last edited by
            #5

            add connection string to app.Config file under tag such as

            right click on solution explorer second and add reference System.Configuration

            string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["connStr1"].ConnectionString;
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connStr);
            conn.Open();

            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