Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

mdb Password

0 views
Skip to first unread message

Zuzar Ladkawala

unread,
Nov 24, 2002, 10:18:46 PM11/24/02
to
Hi Jassim,
I am unaware if u can check if the password exists in the Access DB or not
but, you can programmatically set, change, or remove a database password by
using the ALTER DATABASE keyword with the following syntax:
ALTER DATABASE PASSWORD NewPassword OldPassword.
Kindly Go through the code below which has 2 methods , the 1st one will
change the password of ur access DB and the 2nd one will change ur existing
password:

1) Private Function CreateDBPassword(ByVal Password As String, _
ByVal Path As String) As Boolean
Dim objConn as ADODB.Connection
Dim strAlterPassword as String
On Error GoTo CreateDBPassword_Err
' Create the SQL string to initialize a database password.
strAlterPassword = "ALTER DATABASE PASSWORD [Password] NULL;"

' Open the unsecured database.
Set objConn = New ADODB.Connection
With objConn
.Mode = adModeShareExclusive
.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data " & _
"Source=Path;"

' Execute the SQL statement to secure the database.
.Execute (strAlterPassword)
End With

' Clean up objects.
objConn.Close
Set objConn = Nothing

' Return true if successful.
CreateDBPassword = True

CreateDBPassword_Err:
Msgbox Err.Number & ":" & Err.Description
CreateDBPassword = False
End Function

2) Private Function ChangeDBPassword(ByVal OldPassword As String, _
ByVal NewPassword As String, ByVal Path As String) As Boolean
Dim objConn as ADODB.Connection
Dim strAlterPassword as String

On Error GoTo ChangeDBPassword_Err

' Create the SQL string to change the database password.
strAlterPassword = "ALTER DATABASE PASSWORD [NewPassword]
[OldPassword];"

' Open the secured database.
Set objConn = New ADODB.Connection
With objConn
.Mode = adModeShareExclusive
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Jet OLEDB:Database Password") = "OldPassword"
.Open "Data Source=Path;"

' Execute the SQL statement to change the password.
.Execute (strAlterPassword)
End With

' Clean up objects.
objConn.Close
Set objConn = Nothing

ChangeDBPassword = True

ChangeDBPassword_Err:
Msgbox Err.Number & ":" & Err.Description
ChangeDBPassword = False
End Function

Regards,
Zuzar.L.


"Jassim Rahma" <jra...@hotmail.com> wrote in message
news:13f7101c29418$8feaa240$8df82ecf@TK2MSFTNGXA02...
> how can I check if and mdb password is password protected
> or not? I need to write a code to check if the the mdb
> file was not password, then setup a password for it.


KGK [.NET MVP]

unread,
Nov 25, 2002, 7:20:31 AM11/25/02
to
Hi!

Unless you know the MDB password, you cannot change it. So, essentially, a
password protected MDB will throw an exception when attempted to open using
an incorrect password (you can use this to check if its password protected).

That said, if you know the password, you can change it. Have a look at this
link which exemplifies the same using SQL:

http://www.dbmaker.com.tw/reference/manuals/sql/commands/alterpassword.html

--
Kumar Gaurav Khanna
*************************************************************************
"I can't be Garbage Collected... I am pinned to .NET"
WinToolZone @ http://www.wintoolzone.com/
eXPerience.NET @ http://www.experiencedotnet.com/

"Jassim Rahma" <jra...@hotmail.com> wrote in message
news:13f7101c29418$8feaa240$8df82ecf@TK2MSFTNGXA02...
> how can I check if and mdb password is password protected
> or not? I need to write a code to check if the the mdb
> file was not password, then setup a password for it.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.422 / Virus Database: 237 - Release Date: 20-Nov-2002


0 new messages