How to get connection string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SF

    #1

    How to get connection string

    Hi

    How to get connection string from web.config?

    SF


  • Mark Rae [MVP]

    #2
    Re: How to get connection string

    "SF" <xyz@yahoo.comw rote in message
    news:uevUF9m0IH A.4948@TK2MSFTN GP02.phx.gbl...
    How to get connection string from web.config?
    strConnectionSt ring =
    System.Configur ation.Configura tionManager.Con nectionStrings["SQLConnectionS tring"].ConnectionStri ng;


    --
    Mark Rae
    ASP.NET MVP


    Comment

    • Cowboy \(Gregory A. Beamer\)

      #3
      Re: How to get connection string

      //C#
      string connectionStrin g =
      ConfigurationMa nager.Connectio nStrings["connStringName "].ToString();

      'VB
      Dim connectionStrin g as String = _
      ConfigurationMa nager.Connectio nStrings("connS tringName").ToS tring()

      --
      Gregory A. Beamer
      MVP, MCP: +I, SE, SD, DBA

      Subscribe to my blog


      or just read it:


      *************** *************** *************** ****
      | Think outside the box!
      |
      *************** *************** *************** ****
      "SF" <xyz@yahoo.comw rote in message
      news:uevUF9m0IH A.4948@TK2MSFTN GP02.phx.gbl...
      Hi
      >
      How to get connection string from web.config?
      >
      SF
      >

      Comment

      • Cyril Gupta

        #4
        Re: How to get connection string

        Connection string ....

        Now you know how, so let me tell you something interesting.

        If someone gets hold of your connectionstrin g, they can potentially
        access your db (cause your connectionstrin g has the db user name, and
        pwd). Remember never to use a literal connection string, it's best to
        put it in web config.

        If possible use Windows authentication, and you will be safer, cause
        you would not have user id and pwd in the connectionstrin g, and nobody
        would be able to gain access to the db using those.

        Cheers!
        Cyril Gupta

        Comment

        • Mark Rae [MVP]

          #5
          Re: How to get connection string

          "Cyril Gupta" <cyrilgupta@gma il.comwrote in message
          news:4a970650-a2cf-485c-821a-51beb7e75738@d1 9g2000prm.googl egroups.com...
          it's best to put it in web config.
          That's what the OP asked for..


          --
          Mark Rae
          ASP.NET MVP


          Comment

          Working...