简体   繁体   English

创建一个密码保护的Access数据库

[英]creating a password protected Access database

Using Visual Studio 2010 with a C# WPF project. 将Visual Studio 2010与C#WPF项目一起使用。 I know how to create an Access 2000-2003 db file using the ADOX namespace. 我知道如何使用ADOX命名空间创建Access 2000-2003 db文件。

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

Connect and open the database: 连接并打开数据库:

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

//connect to it with a password
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + _dbPath + ";User Id=admin;Password=myPassword;"

I want to create the file password protected: 我想创建受密码保护的文件:

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

This produces an error at runtime: 这会在运行时产生错误:

Cannot start your application. 无法启动您的应用程序。 The workgroup information file is missing or opened exclusively by another user. 工作组信息文件丢失或由另一个用户专门打开。

When I create without the password, the database is created successfully. 当我创建时没有密码时,数据库创建成功。

How can I create a password protected Access database with this strategy? 如何使用此策略创建受密码保护的Access数据库?

If you mean a database password, rather than user level security, which requires a workgroup file, you can change the connection string to include: 如果您指的是数据库密码而不是需要工作组文件的用户级安全性,则可以更改连接字符串以包括:

 Jet OLEDB:Database Password=MyDbPassword;

That is: 那是:

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

-- http://www.connectionstrings.com/access -http://www.connectionstrings.com/access

Using the information here: http://support.microsoft.com/kb/317881 , with some minor changes: 使用此处的信息: http : //support.microsoft.com/kb/317881 ,进行一些小的更改:

ADOX._Catalog cat = new ADOX.Catalog();

cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=PW;" +
       "Data Source=C:\\Docs\\NewMDB.mdb;");

I find I can create a password protected Access database. 我发现可以创建一个受密码保护的Access数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM