Page 1 of 1

การเชื่อมต่อ excel กับ encrypted password access 2013

Posted: Thu Jul 24, 2014 10:36 am
by tharinster
รบกวนหน่อยครับ ผมมีปัญหานี้มานาน หาคำตอบไม่ได้สักที ผมทำการเชื่อมต่อ MS Excel 2013 กับ ฐานข้อมูล MS Access 2013 ผ่าน code VBA

ถ้าเป็นการเชื่อมต่อปกติ โดยที่ MS Access Database ไม่ได้ติด password สามารถเชื่อมต่อได้ไม่มีปัญหา แต่พอผมใส่ password ให้ MS Access ผมยังหาทางเชื่อมต่อมันไม่ได้สักที วิธีที่ผมทำ และ environment ของผมเป็นดังนี้ครับ

Windows 8 32-bit
MS Office 2013 Professional Plus 2013

Code: Select all

Private Const myPATH As String = "E:\MyApplications\"
Private Const myDBFILENAME As String = "myDB.accdb"

Sub myDataAccess()
Dim oConn As New ADODB.Connection
Dim oRs As New ADODB.Recordset
Dim sDBFile As String
Dim sSQL As String
Dim i As Integer

sDBFile = myPATH + myDBFILENAME

With oConn
    .Provider = "Microsoft.ACE.OLEDB.12.0"
    .ConnectionString = "Data Source=" + sDBFile
    '.Properties("Data Source") = sDBFile
    .Properties("Jet OLEDB:Database Password") = "xxxxxx-xxx"
    .Open
End With

If oConn.State <> adStateOpen Then Exit Sub

sSQL = "SELECT * FROM Employees"

oRs.CursorLocation = adUseClient
'source,actconn,cursortyp,locktyp,opt
oRs.Open sSQL, oConn

MsgBox oRs.RecordCount

oRs.Close
oConn.Close
End Sub
Error คือ
Run-time error '-2147217843(80040e4d)':
Not a valid password

สิ่งที่ผมสังเกตุคือ ไม่ว่าผมจะใส่ code .Properties("Jet OLEDB:Database Password") = "xxxxxx-xxx" หรือไม่ใส่ ผมก็จะได้ error นี้

รบกวนขอคำแนะนำด้วยครับ

Re: การเชื่อมต่อ excel กับ encrypted password access 2013

Posted: Thu Jul 24, 2014 6:20 pm
by snasui
:D ลองดู Connection String สำหรับการติดต่อ Database แบบมี Password ที่นี่ครับ https://www.connectionstrings.com/ace-o ... -password/

Re: การเชื่อมต่อ excel กับ encrypted password access 2013

Posted: Thu Jul 24, 2014 6:49 pm
by tharinster
ขอบคุณมากๆครับ ทำได้แล้วครับ ลองอ่านจาก link ที่ให้มา พอดีเห็นประโยคที่ว่า In Access; try options and choose 2007 encryption method instead. เลยลองดู

โดยการเข้าไปที่ Options > Client Settings > เลื่อนไปหาหัวข้อ Encryption Methods

แล้วเปลี่ยนตัวเลือกจาก "Use Default Encryption (Higher Security)" เป็น "Use legacy encryption (good for reverse compatability and multi-user database"

เรียบร้อย ผ่านแล้ว :)