Provider=Microsoft.Jet.OLEDB.4.0;Password=a;Data Source=D:\database\database.mdb;Persist Security Info=True 连不上,报错“The Workgroup information is missing or opened exclusively by another user”
对access文件加密.即程序开始运行时.用TFileStream读取指定长度的字节是否为,提前写入的 数据,如果是则 begin 数据库没有被非法更改. 用TFileStream读取指定长度的字节(即加密点) 通过自己的算法还原.写回数据库(或生成临时数据库). 连接数据库. end; 退出时: 删除临时库或(加密数据库 或者不用密码,用权限,在登登陆时存On_load加入 Option Compare Database Sub SetStartupProperties() Const DB_Text As Long = 10 Const DB_Boolean As Long = 1 ChangeProperty "StartupForm", DB_Text, "Customers" ChangeProperty "StartupShowDBWindow", DB_Boolean, False ChangeProperty "StartupShowStatusBar", DB_Boolean, False ChangeProperty "AllowBuiltinToolbars", DB_Boolean, False ChangeProperty "AllowFullMenus", DB_Boolean, True ChangeProperty "AllowBreakIntoCode", DB_Boolean, False ChangeProperty "AllowSpecialKeys", DB_Boolean, True ChangeProperty "AllowBypassKey", DB_Boolean, True End SubFunction ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer Dim dbs As Object, prp As Variant Const conPropNotFoundError = 3270 Set dbs = CurrentDb On Error GoTo Change_Err dbs.Properties(strPropName) = varPropValue ChangeProperty = TrueChange_Bye: Exit FunctionChange_Err: If Err = conPropNotFoundError Then ' 找不到属性。 Set prp = dbs.CreateProperty(strPropName, _ varPropType, varPropValue) dbs.Properties.Append prp Resume Next Else ' 未知的错误'。 ChangeProperty = False Resume Change_Bye End If End Function Private Sub Command0_Click() On Error GoTo Err_Command0_Click DoCmd.CloseExit_Command0_Click: Exit SubErr_Command0_Click: MsgBox Err.Description Resume Exit_Command0_Click
End Sub Private Sub Command1_Click() ChangeProperty "AllowBypassKey", DB_Boolean, True
If Me!UesrName = "wyn" And Me!Password = "085477" Then
Else MsgBox "密码错误" End If
End Sub Private Sub Command2_Click() ChangeProperty "AllowBypassKey", DB_Boolean, Flase DoCmd.Close End SubPrivate Sub Form_Load() ChangeProperty "AllowBypassKey", DB_Boolean, False End Sub
连不上,报错“The Workgroup information is missing or opened exclusively by another user”
'User ID=Admin;' +
'Data Source=' + ExtractFilePath(Application.ExeName) + 'data\dqx.mdb;' +
'Mode=ReadWrite;Extended Properties="";' +
'Jet OLEDB:System database="";' +
'Jet OLEDB:Registry Path="";' +
'Jet OLEDB:Database Password=administrator;' + //HERE
'Jet OLEDB:Engine Type=5;' +
'Jet OLEDB:Database Locking Mode=1;' +
'Jet OLEDB:Global Partial Bulk Ops=2;' +
'Jet OLEDB:Global Bulk Transactions=1;' +
'Jet OLEDB:New Database Password="";' +
'Jet OLEDB:Create System Database=False;' +
'Jet OLEDB:Encrypt Database=False;' +
'Jet OLEDB:Don''t Copy Locale on Compact=False;' +
'Jet OLEDB:Compact Without Replica Repair=False;' +
'Jet OLEDB:SFP=False';
'User ID=Admin;' +
'Data Source=' + ExtractFilePath(Application.ExeName) + 'data\dqx.mdb;' +
'Mode=ReadWrite;Extended Properties="";' +
'Jet OLEDB:System database="";' +
'Jet OLEDB:Registry Path="";' +
'Jet OLEDB:Database Password=*****;' + //HERE
'Jet OLEDB:Engine Type=5;' +
'Jet OLEDB:Database Locking Mode=1;' +
'Jet OLEDB:Global Partial Bulk Ops=2;' +
'Jet OLEDB:Global Bulk Transactions=1;' +
'Jet OLEDB:New Database Password="";' +
'Jet OLEDB:Create System Database=False;' +
'Jet OLEDB:Encrypt Database=False;' +
'Jet OLEDB:Don''t Copy Locale on Compact=False;' +
'Jet OLEDB:Compact Without Replica Repair=False;' +
'Jet OLEDB:SFP=False';
就是//HERE那句
数据,如果是则
begin
数据库没有被非法更改.
用TFileStream读取指定长度的字节(即加密点) 通过自己的算法还原.写回数据库(或生成临时数据库).
连接数据库.
end;
退出时:
删除临时库或(加密数据库
或者不用密码,用权限,在登登陆时存On_load加入
Option Compare Database
Sub SetStartupProperties()
Const DB_Text As Long = 10
Const DB_Boolean As Long = 1
ChangeProperty "StartupForm", DB_Text, "Customers"
ChangeProperty "StartupShowDBWindow", DB_Boolean, False
ChangeProperty "StartupShowStatusBar", DB_Boolean, False
ChangeProperty "AllowBuiltinToolbars", DB_Boolean, False
ChangeProperty "AllowFullMenus", DB_Boolean, True
ChangeProperty "AllowBreakIntoCode", DB_Boolean, False
ChangeProperty "AllowSpecialKeys", DB_Boolean, True
ChangeProperty "AllowBypassKey", DB_Boolean, True
End SubFunction ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
Dim dbs As Object, prp As Variant
Const conPropNotFoundError = 3270 Set dbs = CurrentDb
On Error GoTo Change_Err
dbs.Properties(strPropName) = varPropValue
ChangeProperty = TrueChange_Bye:
Exit FunctionChange_Err:
If Err = conPropNotFoundError Then ' 找不到属性。
Set prp = dbs.CreateProperty(strPropName, _
varPropType, varPropValue)
dbs.Properties.Append prp
Resume Next
Else
' 未知的错误'。
ChangeProperty = False
Resume Change_Bye
End If
End Function
Private Sub Command0_Click()
On Error GoTo Err_Command0_Click
DoCmd.CloseExit_Command0_Click:
Exit SubErr_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
End Sub
Private Sub Command1_Click()
ChangeProperty "AllowBypassKey", DB_Boolean, True
If Me!UesrName = "wyn" And Me!Password = "085477" Then
Else
MsgBox "密码错误"
End If
End Sub
Private Sub Command2_Click()
ChangeProperty "AllowBypassKey", DB_Boolean, Flase
DoCmd.Close
End SubPrivate Sub Form_Load()
ChangeProperty "AllowBypassKey", DB_Boolean, False
End Sub