请教关于access数据文件的加密问题
用代码动态创建一个access数据库文件,并给access数据文件加密,出现以下错误提示:
代码:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim cmm As OleDbCommand
Dim cnn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\a1.mdb")
cnn.Open()
cmm = New OleDbCommand("ALTER DATABASE PASSWORD 123456 null", cnn)
cmm.ExecuteNonQuery()
cnn.Close()
cmm = Nothing
cnn = Nothing
End Sub
请大家帮个忙,有没有方法,直接在动态创建数据库文件时,就把密码也加进去呢?
------解决方案-------------------- Dim wrkDefault As Workspace
Dim dbsNew As Database
Dim tdfNew As TableDef
Dim NewDB As Database
Set wrkDefault = DBEngine.Workspaces(0)
Set dbsNew = wrkDefault.CreateDatabase("d:\NewDB.mdb", dbLangGeneral, dbEncrypt)
dbsNew.NewPassword "", "123" '设置数据库密码为123
dbsNew.Execute "Create Table Info(Term text(10),Tzh text(5))"
Set wrkDefault = Nothing
Set dbsNew = Nothing
MsgBox "数据库创建成功!"
------解决方案--------------------上面的access创建用的是dao,adodx也可以实现