在vb6中怎么样用ADO来设置和修改access数据库的密码??

yzisyz 2003-08-20 02:50:48
在vb6中怎么样用ADO来设置和修改access数据库的密码??
...全文
123 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yzisyz 2003-08-20
  • 打赏
  • 举报
回复
原来是用sql语句呀!ok,收到,给分。
谢了
道素 2003-08-20
  • 打赏
  • 举报
回复

http://expert.csdn.net/Expert/topic/2029/2029652.xml?temp=.1231806

以下代码来自MSDN:
http://support.microsoft.com/?kbid=304915
DAO的方法很简单,我就不说了,而且用DAO的很少
添加密码:
Sub ADOAddPW()
Dim cn As ADODB.Connection
Dim newpassword As String
Dim NotValid As Integer
Dim sqlExecStr As String

Set cn = CurrentProject.Connection
On Error Resume Next

' Test to see if the database is open exclusively.
If cn.Mode <> 12 Then
MsgBox "Your database is not opened exclusively", vbCritical
Exit Sub
End If

RetryPassword:
newpassword = InputBox("Please enter new database password", "Database Password" _
, "New Database Password")

' Select case for inputbox.

Select Case newpassword

' Case where the cancel button was pressed.

Case "New Database Password"
MsgBox "No Database password set"
Exit Sub

' Case where the OK button was pressed without entering data.

Case ""
NotValid = MsgBox("You have not entered a valid password, or clicked the cancel button" & Chr(10) & Chr(13) & _
"Do you want to change the database password?", vbCritical + vbYesNo)
If NotValid = 6 Then
GoTo RetryPassword
Else
Exit Sub
End If

'If any data is entered other than the default value.

Case Else
sqlExecStr = "ALTER Database Password " & newpassword & "``"
CurrentProject.Connection.Execute sqlExecStr
MsgBox "Database password has been set"

End Select

End Sub


修改密码:
Sub ResetDBPassword()
Dim cn As ADODB.Connection
Dim sqlExecStr As String
Dim ResetQuestion As Integer

Set cn = CurrentProject.Connection
On Error Resume Next

' Test to see if the database is open exclusively.
If cn.Mode <> 12 Then
MsgBox "Your database is not opened exclusively", vbCritical
Exit Sub
End If
ResetQuestion = MsgBox("You have selected to reset the database" & _
Chr(10) & Chr(13) & "to a blank password. Do you want to continue?", vbQuestion + vbYesNo, _
"Reset Database Password")

'Reset database password based on answer to message box.

If ResetQuestion = 6 Then
sqlExecStr = "ALTER DATABASE PASSWORD `` DBPassword"
CurrentProject.Connection.Execute sqlExecStr
MsgBox "Database Password has been reset."
Else
MsgBox "Database password has not been reset"
Exit Sub
End If

End Sub
道素 2003-08-20
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/2029/2029652.xml?temp=.1231806

以下代码来自MSDN:
http://support.microsoft.com/?kbid=304915
DAO的方法很简单,我就不说了,而且用DAO的很少
添加密码:
Sub ADOAddPW()
Dim cn As ADODB.Connection
Dim newpassword As String
Dim NotValid As Integer
Dim sqlExecStr As String

Set cn = CurrentProject.Connection
On Error Resume Next

' Test to see if the database is open exclusively.
If cn.Mode <> 12 Then
MsgBox "Your database is not opened exclusively", vbCritical
Exit Sub
End If

RetryPassword:
newpassword = InputBox("Please enter new database password", "Database Password" _
, "New Database Password")

' Select case for inputbox.

Select Case newpassword

' Case where the cancel button was pressed.

Case "New Database Password"
MsgBox "No Database password set"
Exit Sub

' Case where the OK button was pressed without entering data.

Case ""
NotValid = MsgBox("You have not entered a valid password, or clicked the cancel button" & Chr(10) & Chr(13) & _
"Do you want to change the database password?", vbCritical + vbYesNo)
If NotValid = 6 Then
GoTo RetryPassword
Else
Exit Sub
End If

'If any data is entered other than the default value.

Case Else
sqlExecStr = "ALTER Database Password " & newpassword & "``"
CurrentProject.Connection.Execute sqlExecStr
MsgBox "Database password has been set"

End Select

End Sub


修改密码:
Sub ResetDBPassword()
Dim cn As ADODB.Connection
Dim sqlExecStr As String
Dim ResetQuestion As Integer

Set cn = CurrentProject.Connection
On Error Resume Next

' Test to see if the database is open exclusively.
If cn.Mode <> 12 Then
MsgBox "Your database is not opened exclusively", vbCritical
Exit Sub
End If
ResetQuestion = MsgBox("You have selected to reset the database" & _
Chr(10) & Chr(13) & "to a blank password. Do you want to continue?", vbQuestion + vbYesNo, _
"Reset Database Password")

'Reset database password based on answer to message box.

If ResetQuestion = 6 Then
sqlExecStr = "ALTER DATABASE PASSWORD `` DBPassword"
CurrentProject.Connection.Execute sqlExecStr
MsgBox "Database Password has been reset."
Else
MsgBox "Database password has not been reset"
Exit Sub
End If

End Sub
wssqsh 2003-08-20
  • 打赏
  • 举报
回复
localcon1:先用oldpassword打开待更改密码的ACCESS库
localcon1.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\localdb.mdb;" & "Mode=Share Deny Read|Share Deny Write;Persist Security Info=False;Jet OLEDB:Database Password=" & oldpassword
wssqsh 2003-08-20
  • 打赏
  • 举报
回复
localcon1.Execute "Alter Database password " & newpassword & " " & oldpassword

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧