FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour string connection MS Access
Posts: 357
Joined: Thu Nov 02, 2006 06:53 PM
string connection MS Access
Posted: Mon Aug 19, 2013 06:36 PM

wthat is string connection Ms Acces to mdb file with password

best regard
kajot

best regards

kajot
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: string connection MS Access
Posted: Mon Aug 19, 2013 07:15 PM
kajot

Here is a sample connection string for Ms Access with a password... see the variable xString.

Rick Lipkin
Code (fw): Select all Collapse
//-- get location of .exe assuming the .mdb is in the same folder //

cFILE := GetModuleFileName( GetInstance() )
aDIR  := DIRECTORY( cFILE )

// where .exe started from is default directory //

nSTART := RAT( "\", cFILE )
cDEFA  := SUBSTR(cFILE,1,nSTART-1)

xPROVIDER := "Microsoft.Jet.OLEDB.4.0"
xSOURCE   := cDEFA+"\YourTable.mdb"
xPASSWORD := "xxxxxx"

xSTRING := 'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Jet OLEDB:Database Password='+xPASSWORD
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: string connection MS Access
Posted: Mon Aug 19, 2013 08:20 PM

From FWH 13.06 onwards we can open access (mdb or accdb) files with password using:

oCn := FW_OpenAdoConnection( <cmdbfilename>, <cpassword> )

The function internally builds the proper connection string.

Regards



G. N. Rao.

Hyderabad, India
Posts: 1303
Joined: Tue Jul 21, 2009 08:12 AM
Re: string connection MS Access
Posted: Tue Aug 20, 2013 08:41 AM

Mr. Nages,

In source\function\adofuncions.prg this is what I have:

function Fw_OpenAdoConnection( cConnStr, lShowError )

Nothing about password.

Muchas gracias. Many thanks.



Un saludo, Best regards,



Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]



Implementando MSVC 2010, FWH64 y ADO.



Abandonando uso xHarbour y SQLRDD.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: string connection MS Access
Posted: Tue Aug 20, 2013 04:32 PM

Mr Lucas

Regret my inaccuracy in the syntax.
The correct syntax is:
oCn := FW_OpenAdoConnection( "<cmdbfilename>,<cpassword>" )

Example:
Create a password protected mdb file with:
FW_CreateMDB( "c:\mydata\tutor05.mdb", "mypassword" )

and open it with
oCn := FW_OpenAdoConnection( "c:\mydata\tutor05.mdb,mypassword" )
OR
oCn := FW_OpenAdoConnection( { "c:\mydata\tutor05.mdb", "mypassword" } )

Regards



G. N. Rao.

Hyderabad, India
Posts: 357
Joined: Thu Nov 02, 2006 06:53 PM
Re: string connection MS Access
Posted: Wed Aug 21, 2013 04:36 PM

thanks for answer

but if I use
cPath := cFilePath( ExeName() )
xSOURCE := cPATH+"waga.mdb"
xPASSWORD := "123456"

oCon := FW_OpenAdoConnection( xSOURCE,xPASSWORD)

cSQL:="select idklienta, nazwa, adres, nip from Klienci"
oRes := FW_OpenRecordSet( oCon, cSQL )

the function FW_OpenRecordSet( oCon, cSQL ) retrun error openning table Klienci

best regards
kajot

best regards

kajot
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: string connection MS Access
Posted: Wed Aug 21, 2013 10:51 PM

Please use:
oCon := FW_OpenAdoConnection( { xSOURCE, xPASSWORD } )

or

oCon := FW_OpenAdoConnection( xSOURCE + "," + xPASSWORD)

Regards



G. N. Rao.

Hyderabad, India
Posts: 357
Joined: Thu Nov 02, 2006 06:53 PM
Re: string connection MS Access
Posted: Fri Aug 23, 2013 06:45 AM

if I used function
oCon := FW_OpenAdoConnection( xSOURCE + "," + xPASSWORD)

the database opened good, but the function FW_OpenRecordSet can't open the table

cSQL:="select idklienta, nazwa, adres, nip from Klienci"
oRes := FW_OpenRecordSet( oCon, cSQL )

best regards
kajot

best regards

kajot
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: string connection MS Access
Posted: Fri Aug 23, 2013 05:35 PM
It is working here for me.
Example code:
Code (fw): Select all Collapse
function TestPW

   local oCn, oRs
   local cmdb := "tutorpw.mdb"
   local pwd  := "12345"

   if ! File( cmdb )
      if ! FW_CreateMDB( cmdb, pwd )
         ? "MDB Create Fail"
         return nil
      endif
   endif

   oCn   := FW_OpenAdoConnection( cmdb + ","  pwd )
   if oCn == nil
      ? "Connect fail"
      return nil
   endif

   FW_AdoImportFromDBF( oCn,  "c:\fwh\samples\CUSTOMER.DBF" )

   xbrowser fw_adotables( oCn )

   oRs := FW_OpenRecordSet( oCn, "CUSTOMER" )
   ? oRs:State

   xbrowser oRs
   oRs:Close()
   oCn:Close()

return nil
Regards



G. N. Rao.

Hyderabad, India
Posts: 357
Joined: Thu Nov 02, 2006 06:53 PM
Re: string connection MS Access
Posted: Fri Aug 23, 2013 09:41 PM

thanks a lot

I can't check up our program, because I have FWH v. 12.06

so I got many error

xLINK: error: Unresolved external symbol '_HB_FUN_FW_CREATEMDB referenced from (t.obj)'.

xLINK: error: Unresolved external symbol '_HB_FUN_FW_ADOIMPORTFROMDBF referenced from (t.obj)'.

xLINK: error: Unresolved external symbol '_HB_FUN_FW_ADOTABLES referenced from (t.obj)'.

best regards
kajot

best regards

kajot
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: string connection MS Access
Posted: Fri Aug 23, 2013 09:50 PM

Creation and Opening of MDB files with password is available from 13.06 only.

Regards



G. N. Rao.

Hyderabad, India
Posts: 153
Joined: Tue Aug 05, 2014 09:48 AM
Re: string connection MS Access
Posted: Wed Aug 23, 2017 12:50 PM

Dear All,
I am unable to get connection using
oCn := FW_OpenAdoConnection( cmdb + "," + pwd )
when file extension of Access file is changed from .mdb to .bds
I need help how to connect

Regards, Greetings



Try FWH. You will enjoy it's simplicity and power.!
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: string connection MS Access
Posted: Wed Aug 23, 2017 01:03 PM
bpd2000 wrote:Dear All,
I am unable to get connection using
oCn := FW_OpenAdoConnection( cmdb + "," + pwd )
when file extension of Access file is changed from .mdb to .bds
I need help how to connect


You can try to modify the function FW_AdoConnectionString as well

Code (fw): Select all Collapse
function FW_AdoConnectionString( cConnSpec, nDb )

.../...

      elseif cExt $ "mdb,accdb,bds"
         cRDBMS      := "MSACCESS"

.../...
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 153
Joined: Tue Aug 05, 2014 09:48 AM
Re: string connection MS Access
Posted: Wed Aug 23, 2017 01:16 PM

Thank you for reply
I tested but not succesful
Error as : Error description: Error BASE/1109 Argument error: $

Regards, Greetings



Try FWH. You will enjoy it's simplicity and power.!
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: string connection MS Access
Posted: Wed Aug 23, 2017 01:21 PM
bpd2000 wrote:Thank you for reply
I tested but not succesful
Error as : Error description: Error BASE/1109 Argument error: $


Put before

Code (fw): Select all Collapse
   ? cExt
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces