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. Avoid connecting to a database through a connection string

Avoid connecting to a database through a connection string

Scheduled Pinned Locked Moved Visual Basic
questiondatabaseannouncement
7 Posts 6 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 Kh
    wrote on last edited by
    #1

    Hello, How can I avoid connecting to a database through a connection string? Because everytime I change the database location I should set a new connection string with the new location. Is there a way to avoid this and save the database within the project itself? And keep the connection there no matter where I install the database? Can I still select, update, delete ... from the database? John,

    C L R J A 5 Replies Last reply
    0
    • J John Kh

      Hello, How can I avoid connecting to a database through a connection string? Because everytime I change the database location I should set a new connection string with the new location. Is there a way to avoid this and save the database within the project itself? And keep the connection there no matter where I install the database? Can I still select, update, delete ... from the database? John,

      C Offline
      C Offline
      coolguy0070
      wrote on last edited by
      #2

      you can set connection string in ur web config file

      L 1 Reply Last reply
      0
      • C coolguy0070

        you can set connection string in ur web config file

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        If only this was for ASP.NET...

        1 Reply Last reply
        0
        • J John Kh

          Hello, How can I avoid connecting to a database through a connection string? Because everytime I change the database location I should set a new connection string with the new location. Is there a way to avoid this and save the database within the project itself? And keep the connection there no matter where I install the database? Can I still select, update, delete ... from the database? John,

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          John, Maybe you should check out SQL Server Compact Edition[^]. "SQL Server Compact is a free, easy-to-use embedded database engine that lets developers build robust Windows Desktop and mobile applications that run on all Windows platforms including Windows XP, Vista, Pocket PC, and Smartphone." You can also use SQL Server Express Edition (on localhost) and use a connection string that attaches the database each time you want to connect:

          Driver={SQL Native Client};Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;

          1 Reply Last reply
          0
          • J John Kh

            Hello, How can I avoid connecting to a database through a connection string? Because everytime I change the database location I should set a new connection string with the new location. Is there a way to avoid this and save the database within the project itself? And keep the connection there no matter where I install the database? Can I still select, update, delete ... from the database? John,

            R Offline
            R Offline
            rprateek
            wrote on last edited by
            #5

            Check the following link out it would be helpful for you: Secure Connection and Easy transaction Handling^ In the above link the connection string is read through DBConfig.ini and when you change the database location just change it in the ini file and would work perfectly for your web or desktop applications.

            Blog for Programmers http://www.rprateek.blogspot.com

            1 Reply Last reply
            0
            • J John Kh

              Hello, How can I avoid connecting to a database through a connection string? Because everytime I change the database location I should set a new connection string with the new location. Is there a way to avoid this and save the database within the project itself? And keep the connection there no matter where I install the database? Can I still select, update, delete ... from the database? John,

              J Offline
              J Offline
              Jon_Boy
              wrote on last edited by
              #6

              I'd do something different from the other suggestions listed. I'd create a UDL file within your application directory. Your program will read the UDL for the connect string. If you run your app on another computer/domain, you can easily update the connect string through the UDL's GUI (eliminates the possibility of manually entering in the connectstring in a file and making a mistake). Right click on your desktop and create a .txt file. Rename the file to something like test.udl. Double click it and you'll see what I'm getting at. There's numerous articles on how to read a udl if you need help. Cheers!

              Any suggestions, ideas, or 'constructive criticism' are always welcome.

              1 Reply Last reply
              0
              • J John Kh

                Hello, How can I avoid connecting to a database through a connection string? Because everytime I change the database location I should set a new connection string with the new location. Is there a way to avoid this and save the database within the project itself? And keep the connection there no matter where I install the database? Can I still select, update, delete ... from the database? John,

                A Offline
                A Offline
                AlexeiXX3
                wrote on last edited by
                #7

                Store your connection string in the application settings and set all connection objects to the application setting To store an app setting: Right click your project > properties > settings > add your connection string

                Alexei Rodriguez

                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