创建受密码保护的访问数据库。

编程入门 行业动态 更新时间:2024-10-24 00:32:57
本文介绍了创建受密码保护的访问数据库。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用MS Visual Studio 2010,而WPF使用C#。 我知道如何使用ADOX创建访问2000-2003 db文件/>

I`m using MS Visual Studio 2010, and WPF with C#. I know how to create an access 2000-2003 db file using the ADOX

ADOX.CatalogClass cat = new CatalogClass(); string str = "provider=Microsoft.Jet.OleDb.4.0;Data Source=" + _dbPath + ";"; cat.Create(str); cat = null;

我也知道如何连接和打开数据库

And I also knew how to connect and open the database

conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + _dbPath + ";");

如果我用密码手动创建文件来保护它,那么我可以用密码连接它

If I manually create the file with a password to protect it, then I can connect to it with the password

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + _dbPath + ";User Id=admin;Password=myPassword;"

现在,我想创建受密码保护的文件...所以我试过这个:

now, I want to create the file password protected ... so I tried this:

ADOX.CatalogClass cat = new CatalogClass(); string str = "provider=Microsoft.Jet.OleDb.4.0;Data Source=" + _dbPath + ";Password=myPassword;"; cat.Create(str); cat = null;

但运行我的应用程序时遇到此错误: 无法启动您的应用程序。工作组信息文件丢失或由其他用户独占打开。 请注意,当我创建没有密码时,数据库创建成功。

but I got this error when running my application: Cannot start your application. The workgroup information file is missing or opened exclusively by another user. note that when I create without the password, the database is created successfully.

推荐答案

查看此主题 [ ^ ],如果它有帮助。 Have a look at this thread[^], if it helps.

我不确定你是如何从头开始做的。我所做的是将空白数据库文件包含为具有特定密码的资源。然后,我只是将该空白数据库写入文件位置并更改数据库密码。我的代码如下: I'm not sure how you'd do it from scratch. What I do is include a blank database file as a resource with a specific password. Then, I just write that blank database to the file location and alter the database password. My code looks like: <System.Diagnostics.DebuggerStepThrough()> _ Public Function CreateDatabase(ByVal Path As String) As String Dim password As String = "" Dim newPasswordEntry As New PasswordEntry() newPasswordEntry.ShowDialog() newPasswordEntry.Focus() If newPasswordEntry.result = Windows.Forms.DialogResult.OK Then password = newPasswordEntry.value Else Return "" End If Try File.WriteAllBytes(Path, My.Resources.RecoveryPlanDB_BE_Master) Catch ex As Exception MessageBox.Show(ex.Message) End Try 'now change the password Dim cn As New OleDbConnection cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Path & _ ";Jet OLEDB:Database Password=password;" & _ "Mode=Share Deny Read|Share Deny Write;" cn.Open() Dim cmd As New OleDbCommand cmd.Connection = cn cmd.CommandText = "ALTER DATABASE PASSWORD [" & password & "][password]" cmd.ExecuteNonQuery() cn.Close() cmd.Dispose() cn.Dispose() Return password End Function

当然,这是VB,所以你必须改变一点(尤其是访问资源中的文件),但这就是主意。

Of course, that's VB, so you'd have to change a bit (especially the accessing the file in the resources), but that's the idea.

试试 try Database Password=

而不是密码=

更多推荐

创建受密码保护的访问数据库。

本文发布于:2023-11-10 15:55:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1575804.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:密码保护   数据库

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!