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. How do I read cnnection string from web config file

How do I read cnnection string from web config file

Scheduled Pinned Locked Moved ASP.NET
helpworkspace
3 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.
  • T Offline
    T Offline
    Tomic
    wrote on last edited by
    #1

    I had the following code: Dim constr as string Dim mysystem as system.configuration.configuration mysystem=system.web.configuration.webconfigurationmanager.openwebconfigura tion(Nothing) Dim mycon as System.Configuration.ConnectionSettings mycon=mysystem.connectionstrings.connectionstrings("CString1") constr =mycon.connectionstringhe code above returned the error below: "Object not sent to an instance of an object" on the line constr =mycon.connectionstring Please where did I get it wrong. Thanks

    P S 2 Replies Last reply
    0
    • T Tomic

      I had the following code: Dim constr as string Dim mysystem as system.configuration.configuration mysystem=system.web.configuration.webconfigurationmanager.openwebconfigura tion(Nothing) Dim mycon as System.Configuration.ConnectionSettings mycon=mysystem.connectionstrings.connectionstrings("CString1") constr =mycon.connectionstringhe code above returned the error below: "Object not sent to an instance of an object" on the line constr =mycon.connectionstring Please where did I get it wrong. Thanks

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #2

      To read a connection string from web.config using WebConfigurationManager, all you need to do is:

      Dim constr As String = WebConfigurationManager.ConnectionStrings("CString1")

      Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

      1 Reply Last reply
      0
      • T Tomic

        I had the following code: Dim constr as string Dim mysystem as system.configuration.configuration mysystem=system.web.configuration.webconfigurationmanager.openwebconfigura tion(Nothing) Dim mycon as System.Configuration.ConnectionSettings mycon=mysystem.connectionstrings.connectionstrings("CString1") constr =mycon.connectionstringhe code above returned the error below: "Object not sent to an instance of an object" on the line constr =mycon.connectionstring Please where did I get it wrong. Thanks

        S Offline
        S Offline
        Sunil Wise
        wrote on last edited by
        #3

        in web.config: <appSettings> <add key="ConnString" value="server=(local);database=Northwind;Integrated Security=SSPI" /> </appSettings> call in u r web page as Imports System.Web.Configuration dim constr as string constr=ConfigurationManager.ConnectionStrings("ConnString").ConnectionString use this hope this helps

        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