Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Getting data from encyrpted (password prot.) MS Access database

Former Member
0 Likes
607

Hi all,

We are trying to get data from a password protected MS access database, that is located locally on a SAP terminal (like C:\database.mdb)

We can get result from the databases that are not password protected, the password protected file is giving a "Connection error".

How can we put the parameter for the file password?

The MDB file is an older format Access file (2000 or 2002/2003)

Any help is appreciated, thanks,

REPORT  ZMLK_SCALE.

INCLUDE OLE2INCL.

DATA: CON         TYPE OLE2_OBJECT,

       REC         TYPE OLE2_OBJECT.

DATA SQL(1023).

DATA: BEGIN OF SPL OCCURS 0,

VAL(1023),

END OF SPL.

DATA: BEGIN OF GT_KANTAR OCCURS 0,

PLATE_NO(15) ,

QUESTION_2(15) ,

entry_date_time(20) ,

exit_date_time(20) ,

weight_1(10),

weight_2(10),

END OF GT_KANTAR .

PARAMETERS : P_USER(20),

              P_PASS(20),

              P_PATH LIKE BSEG-SGTXT DEFAULT 'C:\data\TRUCK.mdb' .

START-OF-SELECTION .

   IF CON-HEADER IS INITIAL OR CON-HANDLE = -1.

     CREATE OBJECT CON 'ADODB.Connection'.

     IF NOT SY-SUBRC = 0.

       EXIT.

     ENDIF.

     CREATE OBJECT REC 'ADODB.Recordset'.

     IF NOT SY-SUBRC = 0.

       EXIT.

     ENDIF.

   ENDIF.

* MDB CONNETION INFOMATIONS ....

   CONCATENATE 'Provider=' '''Microsoft.Jet.OLEDB.4.0''' ';'

   INTO SQL.

   CONCATENATE SQL 'Password=' P_PASS ';'

   INTO SQL.

   CONCATENATE SQL 'User ID='  P_USER   ';'

   INTO SQL.

   CONCATENATE SQL 'Data Source='  P_PATH ';'

   INTO SQL.

   CONCATENATE SQL 'Mode=' '''Share Deny None'''

   INTO SQL.

* MDB connection ...

   CALL METHOD OF CON 'Open'

     EXPORTING

     #1 = SQL.

   BREAK-POINT .

   IF SY-SUBRC NE 0 .

     WRITE : / 'BaÄŸlantı hatası' .

   ELSE .

     WRITE : / 'BaÄŸlantı baÅŸarılı' .

   ENDIF .

   CHECK SY-SUBRC EQ 0 .

* Query (select) statement ...

   SQL = 'select * from[RECORDS]'.

* Query run ...

   CALL METHOD OF REC 'Open'

     EXPORTING #1 = SQL

     #2 = CON

     #3 = '1'.

   DO.

     CALL METHOD OF REC 'getstring' = SQL

     EXPORTING #1 = '2'  "Do not modify!

               #2 = 1    "Do not modify!

               #3 = '|'  "Do not modify!

               #4 = '|'. "Do not modify!

     IF SY-SUBRC EQ 0.

       REFRESH SPL. CLEAR SPL.

       SPLIT SQL AT '|' INTO TABLE SPL.

       clear GT_KANTAR .

       LOOP AT SPL.

         CASE SY-TABIX.

           WHEN 3.

             GT_KANTAR-PLATE_NO = SPL-VAL.

           WHEN 5.

             GT_KANTAR-QUESTION_2 SPL-VAL.

           when 12 .

             GT_KANTAR-entry_date_time SPL-VAL.

           when 13 .

             GT_KANTAR-exit_date_time SPL-VAL.

           when 14 .

             GT_KANTAR-weight_1 SPL-VAL.

           when 15 .

             GT_KANTAR-weight_2 SPL-VAL.

         ENDCASE.

       ENDLOOP.

       APPEND GT_KANTAR .

     ELSE.

       EXIT.

     ENDIF.

   ENDDO.

   LOOP AT GT_KANTAR.

     WRITE: / GT_KANTAR .

   ENDLOOP.

* CONNETION CLOSE & DESTROY

   FREE OBJECT CON.

   FREE OBJECT REC.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
547

I believe you do not have to pass username.

When we open encrypted pdf file, it just asks for password. Behavior of mdb file could be same.

A Microsoft Support article shows vbscript snippet of ways in which encrypted Access database can be opened through OLE.

Your ABAP code is similar to second code snippet given in article.

Dim MyConn As New ADODB.Connection

Dim strConn As String

strConn = "Data Source=C:\...\JetPassword.MDB;" & _

         "Jet OLEDB:Database Password=MyPwd"

MyConn.Provider = "Microsoft.Jet.OLEDB.4.0"

MyConn.Open strConn

Keeping this as reference, you can modify ABAP code so that connection string stored in variable sql has value "Data Source=path; Jet OLEDB:Database Password=pass"

2 REPLIES 2
Read only

Former Member
0 Likes
548

I believe you do not have to pass username.

When we open encrypted pdf file, it just asks for password. Behavior of mdb file could be same.

A Microsoft Support article shows vbscript snippet of ways in which encrypted Access database can be opened through OLE.

Your ABAP code is similar to second code snippet given in article.

Dim MyConn As New ADODB.Connection

Dim strConn As String

strConn = "Data Source=C:\...\JetPassword.MDB;" & _

         "Jet OLEDB:Database Password=MyPwd"

MyConn.Provider = "Microsoft.Jet.OLEDB.4.0"

MyConn.Open strConn

Keeping this as reference, you can modify ABAP code so that connection string stored in variable sql has value "Data Source=path; Jet OLEDB:Database Password=pass"

Read only

0 Likes
547

Thanks, If someone could point a sample code for ABAP, it would be really nice.