dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Finding database if user installs program on D:\ vice c:\

  1. #1
    Brian May Guest

    Finding database if user installs program on D:\ vice c:\


    I'm trying to set my quizzer program install in any directory. It includes
    an access 2000 DB. How can I find the the install location of the DB if
    the user changes the default and store the information/look it up each time
    the program runs?

    Thanx in advance

    Brian

  2. #2
    Abhilash Guest

    Re: Finding database if user installs program on D:\ vice c:\


    well brian.. one way is to use the app.path method.

    The app.path method gives u the active directory or the directory from where
    the application is running..ie., u have ur application say quizzer installed
    at c:\temp then app.path will return you the path c:\temp.And since u have
    a database named say qizdb.mdb installed in the same directory i.e., c:\temp
    then u can easily use for ex. opening up a connection ..database path=app.path
    & "\" qizdb.mdb. It works fine as long as he installs the database in the
    same directory as the application that uses it....
    I guess this should solve ur problem

  3. #3
    Rob Edwards Guest

    Re: Finding database if user installs program on D:\ vice c:\

    Use app.path to determine the location of the application. Then using the
    code i attached as a class pass the app.path value to DBPath, the type of DB
    to DBType and the Name/filename of the DB to DBName. The call MakeDBString
    to get your ADO Connection string.

    One thing i like to do is to make the Object of the class public in my main
    module and initalize it at the beginning of the program. Then anytime i
    need the DBString i just call the object and method.

    One nice feature to this is that if done right, you can code your app for
    Access and then by specifying "SQL Server" as the DBType, the SQLServer
    machine name as DBPath, and the Database Name in SQLServer as the DBName
    value, it will create the SQLServer connection string.

    Currently my app will run on either Access or SQL Server just by the user
    specifying the DB Type in an options box and i use SQLDMO to find the SQL
    Server and database.

    Example Code
    Dim DBConn as New cDBConn
    Dim db as ADODB.Connection
    DBConn.DBType = "Access"
    DBConn.DBPath = App.path
    DBConn.DBName = "MyAccessDB.mdb"
    set db = new ADODB.Connection
    db.open DBConn.MakeDBString


    HTH,

    Rob Edwards

    ----------------------------------8< Begin cDBConn.cls Code
    >8------------------------------------------------------------

    ' If this code works, it was written by Rob Edwards (REdwards@aclt.net).
    ' If not, i don't know who wrote it. (Comment blatenly ripped off from Karl
    E. Peterson)
    ' I accept no liability for any damage this code may do (shouldn't do any)

    'local variable(s) to hold property value(s)
    Private mvarDBType As String 'local copy
    Private mvarDBPath As String 'local copy
    Private mvarDBName As String 'local copy
    Public Function MakeDBString(Optional isShape As Boolean = False) As String
    If mvarDBType = "Access" Then
    If isShape Then
    MakeDBString = "Data Provider=Microsoft.Jet.OLEDB.4.0;Data
    Source=" & mvarDBPath & ";Persist Security Info=False"
    Else
    MakeDBString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
    mvarDBPath & ";Persist Security Info=False"
    End If
    ElseIf mvarDBType = "SQL Server" Then
    If isShape Then
    MakeDBString = "Data Provider=SQLOLEDB.1;Integrated
    Security=SSPI;Persist Security Info=False;Initial Catalog=" & DBName &
    ";Data Source=" & DBPath
    Else
    MakeDBString = "Provider=SQLOLEDB.1;Integrated
    Security=SSPI;Persist Security Info=False;Initial Catalog=" & DBName &
    ";Data Source=" & DBPath
    End If
    End If
    End Function

    Public Property Let DBPath(ByVal vData As String)
    'used when assigning a value to the property, on the left side of an
    assignment.
    'Syntax: X.DBPath = 5
    mvarDBPath = vData
    End Property


    Public Property Get DBPath() As String
    'used when retrieving value of a property, on the right side of an
    assignment.
    'Syntax: Debug.Print X.DBPath
    DBPath = mvarDBPath
    End Property



    Public Property Let DBType(ByVal vData As String)
    'used when assigning a value to the property, on the left side of an
    assignment.
    'Syntax: X.DBType = 5
    mvarDBType = vData
    End Property


    Public Property Get DBType() As String
    'used when retrieving value of a property, on the right side of an
    assignment.
    'Syntax: Debug.Print X.DBType
    DBType = mvarDBType
    End Property

    Public Property Let DBName(ByVal vData As String)
    'used when assigning a value to the property, on the left side of an
    assignment.
    'Syntax: X.DBType = 5
    mvarDBName = vData
    End Property


    Public Property Get DBName() As String
    'used when retrieving value of a property, on the right side of an
    assignment.
    'Syntax: Debug.Print X.DBType
    DBName = mvarDBName
    End Property

    ----------------------------------8< End Code >8--------------------------
    "Brian May" <bbjjmay@yahoo.com> wrote in message
    news:3ad1106d$1@news.devx.com...
    >
    > I'm trying to set my quizzer program install in any directory. It

    includes
    > an access 2000 DB. How can I find the the install location of the DB if
    > the user changes the default and store the information/look it up each

    time
    > the program runs?
    >
    > Thanx in advance
    >
    > Brian








Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center