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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Reuse DB connection

Reuse DB connection

Scheduled Pinned Locked Moved Visual Basic
csharpasp-netdatabasevisual-studiosysadmin
4 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.
  • A Offline
    A Offline
    alwinSCH
    wrote on last edited by
    #1

    Hey, Me : Newbie in VS.NET2005 Question : I have an application in which i define a connectionstring, sqlconnection etc. then i can use this connection on this form! But on another form in the same project i need exactly the same DB (Connectionstring,...) and I don't want to type this twice! So if my DB changes of server or gets a new name when the appplication goes live, i only have to change this at one place! I know you can do something like this in ASP.NET special section in WEB.CONFIG, But where do you do this for a normal Application! Thnx A.

    T 1 Reply Last reply
    0
    • A alwinSCH

      Hey, Me : Newbie in VS.NET2005 Question : I have an application in which i define a connectionstring, sqlconnection etc. then i can use this connection on this form! But on another form in the same project i need exactly the same DB (Connectionstring,...) and I don't want to type this twice! So if my DB changes of server or gets a new name when the appplication goes live, i only have to change this at one place! I know you can do something like this in ASP.NET special section in WEB.CONFIG, But where do you do this for a normal Application! Thnx A.

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

      APP.CONFIG how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06

      A 1 Reply Last reply
      0
      • T ToddHileHoffer

        APP.CONFIG how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06

        A Offline
        A Offline
        alwinSCH
        wrote on last edited by
        #3

        And Where do i find this, how do i use it in my code?

        D 1 Reply Last reply
        0
        • A alwinSCH

          And Where do i find this, how do i use it in my code?

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Go to the Project menu, then click Add New Item. In the window that comes up, find and double-click Application Configuration File. A new file called app.config will be added to your project. Double-click this file to open it in an editor window. You'll see a bunch of XML stuff. Under the <configuration> tag, add something that looks like this:

          <configuration>
          <configSections>
          </configSections>
          <appSettings>
          <add key="myConnectionString" value="your connection string goes here!" />
          </appSettings>
          .
          .
          .

          Now, to get this connection string from anywhere inside your app, just use:

          Imports System.Configuration
          .
          .
          .
          Dim connString As String = ConfigurationSettings.AppSettings("myConnectionString")

          Dave Kreskowiak Microsoft MVP - Visual Basic

          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