Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Get Database Path from path stored in .txt file?

Posted on 2004-11-14
4
Medium Priority
?
229 Views
Last Modified: 2010-04-23
I have an access database and I have a .txt file that has the path stored in it.
The file is already in C:/Program Files/ThisOtherProgram/Config.txt and it contains this line;  4,Z:\DataPath\Data.mdb
This is the path that I would like my program to access the database with because depending on which computer you use the path may be different to my database.

How would I open this file, find "4, X:\ThePath\To\The\Database" and use that for my database connection location when my program loads?

Thanks for any code  or help you can provide
0
Comment
Question by:Matrix1000
  • 2
4 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12581028
Hi Matrix1000,

Is the line with the database information:

    4,Z:\DataPath\Data.mdb

going to be the first line in the text file? ...or do we need to "find" it as you said by looking for the "4," as the beginning of the line?

~IM
0
 
LVL 1

Author Comment

by:Matrix1000
ID: 12581518
Right now it is the first line in the file but potentially there could be something else as the first line (like setting 1,2 and 3) So it might be good to look for the "4"
0
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 2000 total points
ID: 12582162
something like this

Dim sr As System.IO.StreamReader = New System.IO.StreamReader("C:/Program Files/ThisOtherProgram/Config.txt")
        Dim line As String
        Dim path As String
        line = sr.ReadLine()
        Do While Not line Is Nothing

            If line.StartsWith("4,") Then
                path = line.Substring(2).Trim
            End If
            line = sr.ReadLine()
        Loop
        sr.Close()

path should now hold your database path
0
 
LVL 1

Author Comment

by:Matrix1000
ID: 12585470
Thanks!   How would I use "path" in the connection string...

        Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Registry Path=;Data Source=""C:/Program Files/ThisOtherProgram/Data.mdb" & _
        "Jet OLEDB:System database=;Jet OLEDB:Global Bulk Transactions=1;Jet OL" & _

Changed to....

        Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Registry Path=;Data Source=""(Path)" & _
        "Jet OLEDB:System database=;Jet OLEDB:Global Bulk Transactions=1;Jet OL" & _

Doesn't work...I did "Private path as String" but it doesn't like the (path) arguement in the statement
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Screencast - Getting to Know the Pipeline

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question