thienfu Posted August 11, 2010 Posted August 11, 2010 hello all, anyone know how to read ms. access database which is locked with password? if not locked with password i know how to read. like below code : expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> Const $conDbFile = "test.mdb" ; it has to be on script current Dir Const $conTable = "db" Const $conOK = 1, $conEdit = 1, $conAdd = 0 Global $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") Global $objDBSystem, $dbDatatBase, $recRecordSet If Setup() = $conOK Then Main() EndIf Func Setup() $objDBSystem = ObjCreate("DAO.DBEngine.36") If $conOK <> FileExists(@ScriptDir & "\" & $conDbFile) Then MsgBox(16, $conProgName, "Database File is not found ") ;Return 0 Exit EndIf $dbDatatBase = $objDBSystem.OpenDatabase(@ScriptDir & "\" & $conDbFile) $recRecordSet = $dbDatatBase.OpenRecordset("Select * From " & $conTable) Return $conOK EndFunc Func Main() $MainGUI = GUICreate("PT. KBI - Schedulle Tenancy", 1000, 350) GUICtrlCreateGroup("Result", 40, 10, 943, 295) $result = $dbDatatBase.OpenRecordset("Select * From db") if ($result.Eof = -1 And $result.Bof =-1) Then ; Blank Table GUISetState() $ResultBox = GUICtrlCreateListView("No| Block | Unit |Owner| Lease |Start Date|End Date| Name of Tenant |",45,25,933,275) _GUICtrlListView_SetExtendedListViewStyle($ResultBox, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) EndIf With $result if $Result.EOF <> true then $ResultBox = GUICtrlCreateListView("No| Block | Unit |Owner| Lease |Start Date|End Date| Name of Tenant |",45,25,933,275) $j=1 While Not $Result.EOF For $i = $j To $j _GUICtrlListView_SetExtendedListViewStyle($ResultBox, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) _GUICtrlListView_AddItem($ResultBox, $j) _GUICtrlListView_AddSubItem($ResultBox, $i - 1, .Fields(1).Value, 1) _GUICtrlListView_AddSubItem($ResultBox, $i - 1, .Fields(2).Value, 2) _GUICtrlListView_AddSubItem($ResultBox, $i - 1, .Fields(3).Value, 3) _GUICtrlListView_AddSubItem($ResultBox, $i - 1, .Fields(4).Value, 4) _GUICtrlListView_AddSubItem($ResultBox, $i - 1, Display_Date(StringLeft($result("Start_date").value, 8)), 5) _GUICtrlListView_AddSubItem($ResultBox, $i - 1, Display_Date(StringLeft($result("end_date").value, 8)), 6) _GUICtrlListView_AddSubItem($ResultBox, $i - 1, .Fields(7).Value, 7) _GUICtrlListView_AddSubItem($ResultBox, $i - 1, .Fields(8).Value, 8) Next $j = $j+1 $Result.Movenext WEnd $Result.Close EndIf EndWith GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd EndFunc Func Display_Date($date) Return StringRight($date, 2) & "/" & StringMid($date, 5, 2) & "/" & StringLeft($date, 4) ; DD/MM/YYYY ; Return StringMid($date, 5, 2) & "/" & StringRight($date, 2) & "/" & StringLeft($date, 4) ; MM/DD/YYYY EndFunc but when that ms. access database i give password will comeout error like attachment. sorry for my bad english, hope u all know what i mean. thankssample.rar
Bert Posted August 11, 2010 Posted August 11, 2010 You may have to look on MSDN to find what you are looking for. The Vollatran project My blog: http://www.vollysinterestingshit.com/
PsaltyDS Posted August 11, 2010 Posted August 11, 2010 So what did your connect string look like when you tried the password? Something like this? Func Setup() Local $dbOptions = True ; Open in exclusive (vice False = shared) mode Local $dbReadOnly = False Local $dbConnect = "MS Access;pwd=" & $sPassword ; $sPassword is Global $objDBSystem = ObjCreate("DAO.DBEngine.36") If $conOK <> FileExists(@ScriptDir & "\" & $conDbFile) Then MsgBox(16, $conProgName, "Database File is not found ") ;Return 0 Exit EndIf $dbDatatBase = $objDBSystem.OpenDatabase(@ScriptDir & "\" & $conDbFile, $dbOptions, $dbReadOnly, $dbConnect) $recRecordSet = $dbDatatBase.OpenRecordset("Select * From " & $conTable) Return $conOK EndFunc Ref: MSDN: DBEngine.OpenDatabase Method Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
thienfu Posted August 12, 2010 Author Posted August 12, 2010 Hello MPH And PsaltyDS, Thanks for advised. Now i can read ms. access using PsaltyDS code Thanks very much.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now