473,289 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

vb.net set access database password

is it possible to set the database password that you can set in access for a
database from a vb.net application?
Nov 20 '05 #1
5 16852
Cor
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
Nov 20 '05 #2
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" <no*@non.com> wrote in message
news:3f**********************@reader21.wxs.nl...
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

Nov 20 '05 #3
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" <sc************@yahoo.com> wrote in message
news:us**************@TK2MSFTNGP11.phx.gbl...
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.

Nov 20 '05 #4
..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" <la******@tampabay.rr.com> wrote in message
news:uW**************@TK2MSFTNGP10.phx.gbl...
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" <sc************@yahoo.com> wrote in message
news:us**************@TK2MSFTNGP11.phx.gbl...
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.


Nov 20 '05 #5
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" <sc************@yahoo.com> wrote in message
news:ew**************@TK2MSFTNGP10.phx.gbl...
.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

Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Pat A | last post by:
We have a dilemma. We are storing our database password in an include file that resides outside of the web root. The password is in plain text. So, no one can get that password because it can't...
6
by: N. Graves | last post by:
Thank you for taking your time to read my question... please offer your knowledge it will be appreciated! I'm writing a ASP Web page to access a Access Database that has a Database Password set....
3
by: alijsyed | last post by:
I am trying to change an existing database password from VB 6. The database is an MS Access 2000 database if this helps How do I do this? Any help is appreciated.
7
by: carl.manaster | last post by:
I'm new to this game. I can find my way around C# without any trouble, and I've used Access, a little bit, in the past. Now a friend wants an application of mine to read from his Access database....
0
by: Jon S via DotNetMonster.com | last post by:
Hi all The below code is compacting a database that has a password. Unfortunately once the below code is complete the database does not have a password anymore. How do I have it so the password...
2
by: daniel | last post by:
Hi all, I'm using Crystal Reports for Visual Studio .NET 2003 against a fixed Access database with a fixed database-level password, using OLEDB. I designed the reports just fine, but I'm not...
3
by: chunket | last post by:
hi, how to change the ms access database password in c#? i search through the web and found one in VB but not in C#. http://support.microsoft.com/kb/170961 Please give some hints. Thank you. ...
2
daffurankan
by: daffurankan | last post by:
HAi , this ankan wanted to know the code how can i change access database password through vb 6.0 code.
16
by: Greg (codepug | last post by:
If one converts that .mdb into an .mde the code is secure but the tables can still be imported. Just for Very Basic protection, I have placed a Password on the database using the "Set Database...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.