Connecting Tech Pros Worldwide Forums | Help | Site Map

vb.net set access database password

scorpion53061
Guest
 
Posts: n/a
#1: Nov 20 '05
is it possible to set the database password that you can set in access for a
database from a vb.net application?



Cor
Guest
 
Posts: n/a
#2: Nov 20 '05

re: vb.net set access database password


Hi Scorpion,

Copied from your own text.
.................................
OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Jet OLEDB:Database Password=;Data Source=" &
..............
"y None;Jet OLEDB:New Database Password=;Jet OLEDB:Create System

What do I mis?

I have never tried it, but I thougth the password was in this string?

(I did give you an answer on this message yesterday, but I think it
disapeared, I hope is will show up soon, it was not that important to send
it twice. But in the answer was that I had nothing against your code, but
that I think that it will not work in some situations).

Cor


scorpion53061
Guest
 
Posts: n/a
#3: Nov 20 '05

re: vb.net set access database password


This sets the password which the user connects with.

What I want to do is to be able to change the password for the database
within vb.net to a password of the users choice.
INside access in the Tools menu there is Security/Set Password. Somehow have
to be able to access that function.

"Cor" <non@non.com> wrote in message
news:3f94e0d9$0$2472$48b97d01@reader21.wxs.nl...[color=blue]
> Hi Scorpion,
>
> Copied from your own text.
> ................................
> OLEDB:Registry Path=;Jet OLEDB:Database L" & _
> "ocking Mode=1;Jet OLEDB:Database Password=;Data Source=" &
> .............
> "y None;Jet OLEDB:New Database Password=;Jet OLEDB:Create System
>
> What do I mis?
>
> I have never tried it, but I thougth the password was in this string?
>
> (I did give you an answer on this message yesterday, but I think it
> disapeared, I hope is will show up soon, it was not that important to send
> it twice. But in the answer was that I had nothing against your code, but
> that I think that it will not work in some situations).
>
> Cor
>
>[/color]


William LaMartin
Guest
 
Posts: n/a
#4: Nov 20 '05

re: vb.net set access database password


Here is some VBA code that I lifted from a Microsoft Access Module that does
what you want in that situation. You should be able to modify it to your
purposes.


Private Sub cmdOk_Click()
Dim conDatabase As ADODB.Connection
Dim SQL As String
Dim intCheckPwd As Integer

On Error GoTo Error_Handler

Set conDatabase = Application.CurrentProject.Connection

'check that both new and confirm passwords are nonempty
If ((IsNull(txtConfirmPwd)) Or (IsNull(txtNewPwd))) Then
MsgBox ("Enter both and new and confirm password")
Exit Sub
End If

'Check that the new and confirmed passwords match.
intCheckPwd = StrComp(txtNewPwd, txtConfirmPwd, vbBinaryCompare)

'Determine if we are changing/clearing the current password
'or setting a new one.
If txtOldPwd.Enabled = False And intCheckPwd = 0 Then
SQL = "ALTER DATABASE PASSWORD " & txtNewPwd & " NULL"
conDatabase.Execute SQL
MsgBox "The new password was successfully set.", vbInformation

'Change the current password.
ElseIf intCheckPwd = 0 Then

'Check that the old password was given.
If IsNull(txtOldPwd) Then
MsgBox "Please enter the current (old) password.", _
vbInformation
txtOldPwd.SetFocus
Exit Sub
End If

SQL = "ALTER DATABASE PASSWORD " & txtNewPwd & " " & txtOldPwd
conDatabase.Execute SQL
MsgBox "The password was successfully changed.", vbInformation

'Password was not confirmed.
Else
MsgBox "The password was not confirmed. Please try again.", _
vbExclamation
txtConfirmPwd = vbNullString
txtConfirmPwd.SetFocus
Exit Sub
End If

'Close out the form and all object variables.
conDatabase.Close
Set conDatabase = Nothing
DoCmd.Close acForm, "frmDBPassword"

Exit Sub
Error_Handler:
MsgBox Err.Description, vbCritical


End Sub


"scorpion53061" <scorpion_53061@yahoo.com> wrote in message
news:usabMb7lDHA.1244@TK2MSFTNGP11.phx.gbl...[color=blue]
> This sets the password which the user connects with.
>
> What I want to do is to be able to change the password for the database
> within vb.net to a password of the users choice.
> INside access in the Tools menu there is Security/Set Password. Somehow[/color]
have[color=blue]
> to be able to access that function.
>[/color]


scorpion53061
Guest
 
Posts: n/a
#5: Nov 20 '05

re: vb.net set access database password


..I got this error would you know what to do about it?
It bombs when I ask the conneciton to connect.

Private Sub cmdOk_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdOk.Click
Dim conDatabase As ADODB.Connection

Dim SQL As String
Dim intCheckPwd As Integer


'On Error GoTo Error_Handler
Dim hi As New ADODB.Connection
Dim DBConnection As String =
"PROVIDER=Microsoft.Jet.OLEDB.4.0;Uid=Admin;Pwd=bu lgaria;DATA
SOURCE=C:\churchdatabase.mdb;"

';password = bulgaria;database = C:\churchdatabase;DataSource =
local"
hi.ConnectionString = DBConnection
'hi.Mode()
'check that both new and confirm passwords are nonempty
If txtConfirmPwd.Text = "" Or txtNewPwd.Text = "" Then
MsgBox("Enter both and new and confirm password")
Exit Sub
End If

'Check that the new and confirmed passwords match.
intCheckPwd = StrComp(txtNewPwd.Text, txtConfirmPwd.Text,
vbBinaryCompare)

'Determine if we are changing/clearing the current password
'or setting a new one.
If txtOldPwd.Enabled = False And intCheckPwd = 0 Then
SQL = "ALTER DATABASE PASSWORD " & txtNewPwd.Text & " NULL"
conDatabase.Execute(SQL)
MsgBox("The new password was successfully set.", vbInformation)

'Change the current password.
ElseIf intCheckPwd = 0 Then

'Check that the old password was given.
If txtOldPwd.Text = "" Then
MsgBox("Please enter the current (old) password.", _
vbInformation)
'txtOldPwd.SetFocus()
Exit Sub
End If

SQL = "ALTER DATABASE PASSWORD " & txtNewPwd.Text & " " &
txtOldPwd.Text
hi.Execute(SQL)
MsgBox("The password was successfully changed.", vbInformation)

'Password was not confirmed.
Else
MsgBox("The password was not confirmed. Please try again.", _
vbExclamation)
txtConfirmPwd.Text = vbNullString
'txtConfirmPwd.SetFocus()
Exit Sub
End If

'Close out the form and all object variables.
conDatabase.Close()
conDatabase = Nothing
'DoCmd.Close(acForm, "frmDBPassword")

Exit Sub
Error_Handler:
MsgBox(Err.Description, vbCritical)
End Sub
"William LaMartin" <lamartin@tampabay.rr.com> wrote in message
news:uWQ9XkAmDHA.2416@TK2MSFTNGP10.phx.gbl...[color=blue]
> Here is some VBA code that I lifted from a Microsoft Access Module that[/color]
does[color=blue]
> what you want in that situation. You should be able to modify it to your
> purposes.
>
>
> Private Sub cmdOk_Click()
> Dim conDatabase As ADODB.Connection
> Dim SQL As String
> Dim intCheckPwd As Integer
>
> On Error GoTo Error_Handler
>
> Set conDatabase = Application.CurrentProject.Connection
>
> 'check that both new and confirm passwords are nonempty
> If ((IsNull(txtConfirmPwd)) Or (IsNull(txtNewPwd))) Then
> MsgBox ("Enter both and new and confirm password")
> Exit Sub
> End If
>
> 'Check that the new and confirmed passwords match.
> intCheckPwd = StrComp(txtNewPwd, txtConfirmPwd, vbBinaryCompare)
>
> 'Determine if we are changing/clearing the current password
> 'or setting a new one.
> If txtOldPwd.Enabled = False And intCheckPwd = 0 Then
> SQL = "ALTER DATABASE PASSWORD " & txtNewPwd & " NULL"
> conDatabase.Execute SQL
> MsgBox "The new password was successfully set.", vbInformation
>
> 'Change the current password.
> ElseIf intCheckPwd = 0 Then
>
> 'Check that the old password was given.
> If IsNull(txtOldPwd) Then
> MsgBox "Please enter the current (old) password.", _
> vbInformation
> txtOldPwd.SetFocus
> Exit Sub
> End If
>
> SQL = "ALTER DATABASE PASSWORD " & txtNewPwd & " " & txtOldPwd
> conDatabase.Execute SQL
> MsgBox "The password was successfully changed.", vbInformation
>
> 'Password was not confirmed.
> Else
> MsgBox "The password was not confirmed. Please try again.", _
> vbExclamation
> txtConfirmPwd = vbNullString
> txtConfirmPwd.SetFocus
> Exit Sub
> End If
>
> 'Close out the form and all object variables.
> conDatabase.Close
> Set conDatabase = Nothing
> DoCmd.Close acForm, "frmDBPassword"
>
> Exit Sub
> Error_Handler:
> MsgBox Err.Description, vbCritical
>
>
> End Sub
>
>
> "scorpion53061" <scorpion_53061@yahoo.com> wrote in message
> news:usabMb7lDHA.1244@TK2MSFTNGP11.phx.gbl...[color=green]
> > This sets the password which the user connects with.
> >
> > What I want to do is to be able to change the password for the database
> > within vb.net to a password of the users choice.
> > INside access in the Tools menu there is Security/Set Password. Somehow[/color]
> have[color=green]
> > to be able to access that function.
> >[/color]
>
>[/color]


William LaMartin
Guest
 
Posts: n/a
#6: Nov 20 '05

re: vb.net set access database password


What error did you receive?

Here is the way I would proceed in VB.Net to open the database. Note to add
a password or make changes to a password, you need to open the database in
exclusive mode as follows:

Dim MyConnection As New System.Data.OleDb.OleDbConnection
MyConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;User
ID=Admin;Jet OLEDB:Database Password=;Data Source=" &
Application.StartupPath.Substring(0, Len(Application.StartupPath) - 3) &
"PasswordExample.mdb;mode=12" 'Mode=adModeShareDenyExclusive"
MyConnection.Open()

If the database already had a password, you would need to include the
password in Password=whatever the passwrod is

"scorpion53061" <scorpion_53061@yahoo.com> wrote in message
news:ewUq9aBmDHA.2080@TK2MSFTNGP10.phx.gbl...[color=blue]
> .I got this error would you know what to do about it?
> It bombs when I ask the conneciton to connect.
>
> Private Sub cmdOk_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles cmdOk.Click
> Dim conDatabase As ADODB.Connection
>
> Dim SQL As String
> Dim intCheckPwd As Integer
>
>
> 'On Error GoTo Error_Handler
> Dim hi As New ADODB.Connection
> Dim DBConnection As String =
> "PROVIDER=Microsoft.Jet.OLEDB.4.0;Uid=Admin;Pwd=bu lgaria;DATA
> SOURCE=C:\churchdatabase.mdb;"
>
> ';password = bulgaria;database = C:\churchdatabase;DataSource =
> local"
> hi.ConnectionString = DBConnection
> 'hi.Mode()
> 'check that both new and confirm passwords are nonempty
> If txtConfirmPwd.Text = "" Or txtNewPwd.Text = "" Then
> MsgBox("Enter both and new and confirm password")
> Exit Sub
> End If
>
> 'Check that the new and confirmed passwords match.
> intCheckPwd = StrComp(txtNewPwd.Text, txtConfirmPwd.Text,
> vbBinaryCompare)
>
> 'Determine if we are changing/clearing the current password
> 'or setting a new one.
> If txtOldPwd.Enabled = False And intCheckPwd = 0 Then
> SQL = "ALTER DATABASE PASSWORD " & txtNewPwd.Text & " NULL"
> conDatabase.Execute(SQL)
> MsgBox("The new password was successfully set.",[/color]
vbInformation)[color=blue]
>
> 'Change the current password.
> ElseIf intCheckPwd = 0 Then
>
> 'Check that the old password was given.
> If txtOldPwd.Text = "" Then
> MsgBox("Please enter the current (old) password.", _
> vbInformation)
> 'txtOldPwd.SetFocus()
> Exit Sub
> End If
>
> SQL = "ALTER DATABASE PASSWORD " & txtNewPwd.Text & " " &
> txtOldPwd.Text
> hi.Execute(SQL)
> MsgBox("The password was successfully changed.",[/color]
vbInformation)[color=blue]
>
> 'Password was not confirmed.
> Else
> MsgBox("The password was not confirmed. Please try again.", _
> vbExclamation)
> txtConfirmPwd.Text = vbNullString
> 'txtConfirmPwd.SetFocus()
> Exit Sub
> End If
>
> 'Close out the form and all object variables.
> conDatabase.Close()
> conDatabase = Nothing
> 'DoCmd.Close(acForm, "frmDBPassword")
>
> Exit Sub
> Error_Handler:
> MsgBox(Err.Description, vbCritical)
> End Sub[/color]


Closed Thread