Open Database from Command line


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Open Database from Command line

  1. #1
    John Guest

    Open Database from Command line


    Dear ladies and gentlemen,

    I have a vb6.0 application. The back end is 2 access 97 database one on the
    network the other on the local drive.


    For local drive:
    Dim cn As ADODB.Connection
    Set cn = New ADODB.Connection
    With cn
    .Provider = "Microsoft.Jet.OLEDB.4.0"
    .Properties("Jet OLEDBatabase Password") = "password"
    .Open "c:\Directory\ localDatabase.mdb"
    End With


    For network :
    Set cn = New ADODB.Connection
    With cn
    .Provider = "Microsoft.Jet.OLEDB.4.0"
    .Properties("Jet OLEDBatabase Password") = "password"
    .Open App.Path & "\NetworkDatabas.mdb"
    End With

    I would like to locate the local database programmatically without using


    .Open "c:\Directory\Databaselocal.mdb"

    I try to use the command line but I can not applied to my code. For Example,

    If I have a shortcut and my target is:

    S:Networkapplication c:\localDatabase.mdb

    And when we create the shortcut we can use any local drive C or D. also how
    can I write this code in my VB application and the ADO.

    Any Ideas will be appreciated. If you have the code will be great help.


    Thank a lot in advance.

    John



  2. #2
    Adam Guest

    Re: Open Database from Command line


    "John" <misbn@yahoo.com> wrote:
    >
    >Dear ladies and gentlemen,
    >
    >I have a vb6.0 application. The back end is 2 access 97 database one on

    the
    >network the other on the local drive.
    >
    >
    >For local drive:
    >Dim cn As ADODB.Connection
    > Set cn = New ADODB.Connection
    > With cn
    > .Provider = "Microsoft.Jet.OLEDB.4.0"
    > .Properties("Jet OLEDBatabase Password") = "password"
    > .Open "c:\Directory\ localDatabase.mdb"
    > End With
    >
    >
    >For network :
    >Set cn = New ADODB.Connection
    >With cn
    > .Provider = "Microsoft.Jet.OLEDB.4.0"
    > .Properties("Jet OLEDBatabase Password") = "password"
    > .Open App.Path & "\NetworkDatabas.mdb"
    >End With
    >
    >I would like to locate the local database programmatically without using
    >
    >
    > .Open "c:\Directory\Databaselocal.mdb"
    >
    >I try to use the command line but I can not applied to my code. For Example,
    >
    >If I have a shortcut and my target is:
    >
    >S:Networkapplication c:\localDatabase.mdb
    >
    >And when we create the shortcut we can use any local drive C or D. also

    how
    >can I write this code in my VB application and the ADO.
    >
    >Any Ideas will be appreciated. If you have the code will be great help.
    >
    >
    >Thank a lot in advance.
    >
    >John
    >
    >

    John,

    You have to write code to get and do something with the argument passed in
    to your app on the command line. Use the Command function. For example:


    Dim sDatabaseFileName as string
    Dim oConneciton as ADODB.Connection

    sDatabaseFileName = Command()
    set oConnection = New ADODB.Connection
    oConneciton.Open sDatabaseFileName





  3. #3
    John Guest

    Re: Open Database from Command line


    Hi Adam

    This code is in my command line (Shortcut).

    C:\Project.exe "DBPath=C:\DirectoryName\DatabaseName.mdb"

    The following is my VB code but it did not work.

    dim sDBPath as string
    dim cn as adodb.connection

    sDBPath= Right(Command,(len(Command)-instr(Command,"=")))
    set cn =new adodb.connection
    cn.password ="password"
    cn.open sDBPath

    Also I tried your code not working ether. Is my command line (shortcut) code
    is right? I am sorry but this the first time I am using this way.

    Any Idea thanks.

    John

    "Adam" <adam.strakna@prometric.com> wrote:
    >
    >"John" <misbn@yahoo.com> wrote:
    >>
    >>Dear ladies and gentlemen,
    >>
    >>I have a vb6.0 application. The back end is 2 access 97 database one on

    >the
    >>network the other on the local drive.
    >>
    >>
    >>For local drive:
    >>Dim cn As ADODB.Connection
    >> Set cn = New ADODB.Connection
    >> With cn
    >> .Provider = "Microsoft.Jet.OLEDB.4.0"
    >> .Properties("Jet OLEDBatabase Password") = "password"
    >> .Open "c:\Directory\ localDatabase.mdb"
    >> End With
    >>
    >>
    >>For network :
    >>Set cn = New ADODB.Connection
    >>With cn
    >> .Provider = "Microsoft.Jet.OLEDB.4.0"
    >> .Properties("Jet OLEDBatabase Password") = "password"
    >> .Open App.Path & "\NetworkDatabas.mdb"
    >>End With
    >>
    >>I would like to locate the local database programmatically without using
    >>
    >>
    >> .Open "c:\Directory\Databaselocal.mdb"
    >>
    >>I try to use the command line but I can not applied to my code. For Example,
    >>
    >>If I have a shortcut and my target is:
    >>
    >>S:Networkapplication c:\localDatabase.mdb
    >>
    >>And when we create the shortcut we can use any local drive C or D. also

    >how
    >>can I write this code in my VB application and the ADO.
    >>
    >>Any Ideas will be appreciated. If you have the code will be great help.
    >>
    >>
    >>Thank a lot in advance.
    >>
    >>John
    >>
    >>

    >John,
    >
    >You have to write code to get and do something with the argument passed

    in
    >to your app on the command line. Use the Command function. For example:
    >
    >
    > Dim sDatabaseFileName as string
    > Dim oConneciton as ADODB.Connection
    >
    > sDatabaseFileName = Command()
    > set oConnection = New ADODB.Connection
    > oConneciton.Open sDatabaseFileName
    >
    >
    >
    >



  4. #4
    Adam Guest

    Re: Open Database from Command line


    "John" <misbn@yahoo.com> wrote:
    >
    >Hi Adam
    >
    >This code is in my command line (Shortcut).
    >
    >C:\Project.exe "DBPath=C:\DirectoryName\DatabaseName.mdb"
    >
    >The following is my VB code but it did not work.
    >
    >dim sDBPath as string
    >dim cn as adodb.connection
    >
    >sDBPath= Right(Command,(len(Command)-instr(Command,"=")))
    >set cn =new adodb.connection
    >cn.password ="password"
    >cn.open sDBPath
    >
    >Also I tried your code not working ether. Is my command line (shortcut)

    code
    >is right? I am sorry but this the first time I am using this way.
    >
    >Any Idea thanks.
    >
    >John
    >
    >"Adam" <adam.strakna@prometric.com> wrote:
    >>
    >>"John" <misbn@yahoo.com> wrote:
    >>>
    >>>Dear ladies and gentlemen,
    >>>
    >>>I have a vb6.0 application. The back end is 2 access 97 database one on

    >>the
    >>>network the other on the local drive.
    >>>
    >>>
    >>>For local drive:
    >>>Dim cn As ADODB.Connection
    >>> Set cn = New ADODB.Connection
    >>> With cn
    >>> .Provider = "Microsoft.Jet.OLEDB.4.0"
    >>> .Properties("Jet OLEDBatabase Password") = "password"
    >>> .Open "c:\Directory\ localDatabase.mdb"
    >>> End With
    >>>
    >>>
    >>>For network :
    >>>Set cn = New ADODB.Connection
    >>>With cn
    >>> .Provider = "Microsoft.Jet.OLEDB.4.0"
    >>> .Properties("Jet OLEDBatabase Password") = "password"
    >>> .Open App.Path & "\NetworkDatabas.mdb"
    >>>End With
    >>>
    >>>I would like to locate the local database programmatically without using
    >>>
    >>>
    >>> .Open "c:\Directory\Databaselocal.mdb"
    >>>
    >>>I try to use the command line but I can not applied to my code. For Example,
    >>>
    >>>If I have a shortcut and my target is:
    >>>
    >>>S:Networkapplication c:\localDatabase.mdb
    >>>
    >>>And when we create the shortcut we can use any local drive C or D. also

    >>how
    >>>can I write this code in my VB application and the ADO.
    >>>
    >>>Any Ideas will be appreciated. If you have the code will be great help.
    >>>
    >>>
    >>>Thank a lot in advance.
    >>>
    >>>John
    >>>
    >>>

    >>John,
    >>
    >>You have to write code to get and do something with the argument passed

    >in
    >>to your app on the command line. Use the Command function. For example:
    >>
    >>
    >> Dim sDatabaseFileName as string
    >> Dim oConneciton as ADODB.Connection
    >>
    >> sDatabaseFileName = Command()
    >> set oConnection = New ADODB.Connection
    >> oConneciton.Open sDatabaseFileName
    >>
    >>
    >>
    >>

    >

    John,

    I think the quotation marks are causing your problem. You do not need them
    and if you use them your code has to compensate for it. Also, you do not
    need the 'DBPath=' in your command line - just the path to the .mdb file
    is fine.

    FYI...

    You can test your command line in the development environment by specifying
    a command line in the 'command line arguments' on the 'make' tab of the project
    properties. This way you can walk through the code and see exactly what
    is happening.

    Adam


  5. #5
    John Guest

    Re: Open Database from Command line


    Thanks a lot Adam for your help it did work.

    John


    "Adam" <adam.strakna@prometric.com> wrote:
    >
    >"John" <misbn@yahoo.com> wrote:
    >>
    >>Hi Adam
    >>
    >>This code is in my command line (Shortcut).
    >>
    >>C:\Project.exe "DBPath=C:\DirectoryName\DatabaseName.mdb"
    >>
    >>The following is my VB code but it did not work.
    >>
    >>dim sDBPath as string
    >>dim cn as adodb.connection
    >>
    >>sDBPath= Right(Command,(len(Command)-instr(Command,"=")))
    >>set cn =new adodb.connection
    >>cn.password ="password"
    >>cn.open sDBPath
    >>
    >>Also I tried your code not working ether. Is my command line (shortcut)

    >code
    >>is right? I am sorry but this the first time I am using this way.
    >>
    >>Any Idea thanks.
    >>
    >>John
    >>
    >>"Adam" <adam.strakna@prometric.com> wrote:
    >>>
    >>>"John" <misbn@yahoo.com> wrote:
    >>>>
    >>>>Dear ladies and gentlemen,
    >>>>
    >>>>I have a vb6.0 application. The back end is 2 access 97 database one

    on
    >>>the
    >>>>network the other on the local drive.
    >>>>
    >>>>
    >>>>For local drive:
    >>>>Dim cn As ADODB.Connection
    >>>> Set cn = New ADODB.Connection
    >>>> With cn
    >>>> .Provider = "Microsoft.Jet.OLEDB.4.0"
    >>>> .Properties("Jet OLEDBatabase Password") = "password"
    >>>> .Open "c:\Directory\ localDatabase.mdb"
    >>>> End With
    >>>>
    >>>>
    >>>>For network :
    >>>>Set cn = New ADODB.Connection
    >>>>With cn
    >>>> .Provider = "Microsoft.Jet.OLEDB.4.0"
    >>>> .Properties("Jet OLEDBatabase Password") = "password"
    >>>> .Open App.Path & "\NetworkDatabas.mdb"
    >>>>End With
    >>>>
    >>>>I would like to locate the local database programmatically without using
    >>>>
    >>>>
    >>>> .Open "c:\Directory\Databaselocal.mdb"
    >>>>
    >>>>I try to use the command line but I can not applied to my code. For Example,
    >>>>
    >>>>If I have a shortcut and my target is:
    >>>>
    >>>>S:Networkapplication c:\localDatabase.mdb
    >>>>
    >>>>And when we create the shortcut we can use any local drive C or D. also
    >>>how
    >>>>can I write this code in my VB application and the ADO.
    >>>>
    >>>>Any Ideas will be appreciated. If you have the code will be great help.
    >>>>
    >>>>
    >>>>Thank a lot in advance.
    >>>>
    >>>>John
    >>>>
    >>>>
    >>>John,
    >>>
    >>>You have to write code to get and do something with the argument passed

    >>in
    >>>to your app on the command line. Use the Command function. For example:
    >>>
    >>>
    >>> Dim sDatabaseFileName as string
    >>> Dim oConneciton as ADODB.Connection
    >>>
    >>> sDatabaseFileName = Command()
    >>> set oConnection = New ADODB.Connection
    >>> oConneciton.Open sDatabaseFileName
    >>>
    >>>
    >>>
    >>>

    >>

    >John,
    >
    >I think the quotation marks are causing your problem. You do not need them
    >and if you use them your code has to compensate for it. Also, you do not
    >need the 'DBPath=' in your command line - just the path to the .mdb file
    >is fine.
    >
    >FYI...
    >
    >You can test your command line in the development environment by specifying
    >a command line in the 'command line arguments' on the 'make' tab of the

    project
    >properties. This way you can walk through the code and see exactly what
    >is happening.
    >
    >Adam
    >



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