adodb connection string question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stephenm1
    New Member
    • Jan 2012
    • 7

    adodb connection string question

    Hey guys,

    I've got a database which I am linking into a form on VB6. The form has only an ADODB function and a Datagrid to display the records.
    I currently have this working fine where I build the connection string and then specify where the database is located.

    However I am wondering if there is anyway to set the connection string used as the database within the folder where the VB project is contained, using the
    chdir (app.path) function perhaps?

    Each time I run my program on another computer I have to reprogram the database path which is quite annoying, any ideas on how to solve this?

    Many thanks,
    Stephen
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Hi

    On the basis that the DB is on you (company?) network then I personaly use udl file(s) to hold my connectuon strings located on the network (although you can put in the directory where your code is running and use this in the udl file path in you program.

    The avantage of this is that if the DB is move or renamed you just point the uld file at the new file/location without any need to recode your program(s) (I have many spreadsheets that create variouse reports/graphs from multiple databases. It is much easier in Excel!!)

    There is an excelent article on uld files in this forum here http://bytes.com/topic/access/insigh...data-link-file

    HTH


    MTB

    Comment

    • thelionheart
      New Member
      • Feb 2012
      • 12

      #3
      my suggestion is try to create a configuration file(external file) wherein the connection string is handled

      here is the step:

      create first a config file to put your connection string named "config.ini ":
      =======
      Driver=MySQL ODBC 3.51 Driver;
      Database=dbfile ;
      UID=root;
      PWD=;
      =======

      write a code in a module:
      ======
      Public cn as New ADODB.Connectio n
      Public FileLocation As String
      Public config_string As String
      Public FileNum


      Public Sub Connection()
      On Error GoTo Disconnect
      FileLocation = App.Path & "\Config\config .ini"
      FileNum = FreeFile
      Open FileLocation For Input As #FileNum
      Do Until EOF(FileNum) = True
      Line Input #FileNum, Data
      config_string = config_string + Data
      Loop
      Close #FileNum

      cn.CursorLocati on = adUseClient
      If cn.State = 1 Then cn.Close
      cn.Open config_string
      Exit Sub
      Disconnect:
      MsgBox Err.Description , vbCritical, Err.Number
      MsgBox "System has been Terminated!", vbExclamation
      End
      End Sub
      ======

      Private Sub Form_Load()
      Call Connection
      End Sub

      Comment

      • rekedtechie
        New Member
        • Feb 2012
        • 51

        #4
        'create an .exe format of your project
        'put your .exe project in the folder where your database can be found.

        'set the Data Source in your Connection String

        Data Source="& app.Path &"/YourDatabaseNam e.mdb;

        'PS: you can also specify subfolders
        'for example your database can be found on the subfolder named "System_dat a"

        'your DataSource look like this..

        Data Source="& app.Path &"/System_data/YourDatabase.md b;

        "make sure there is no spacing between "& and &" because ""&eee&"e" = eeee
        ""&eee& "e" = eee e

        Comment

        Working...