打开与 MS Access 2007 文件的连接时出错:无法打开 MS Office Access 数据库引擎工作组信息文件
无法打开 MS Office Access 数据库引擎工作组信息文件
- 当我发布代码时。
我在代码中尝试做的是创建 MS Access 2007 文件,然后从我的程序中为其设置用户名和密码。我在这里做错了什么?
这里发生错误: objOleDbConnection.Open();
编辑:我做了一些更改,似乎它打开了一个连接,但命令不正确。
现在问题就在这里:
objOleDbCommand.CommandText =
"ALTER USER " + storedAuth.UserName +
" PASSWORD [" + storedAuth.Password + "] []";
整个代码:
// Creating an object allowing me connecting to the database.
OleDbConnection objOleDbConnection = new OleDbConnection();
objOleDbConnection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" +
"Data Source=" + sfdNewFile.FileName + ";Persist Security Info=False";
// Creating command object.
OleDbCommand objOleDbCommand = new OleDbCommand();
objOleDbCommand.Connection = objOleDbConnection;
try
{
objOleDbConnection.Open();
objOleDbCommand.CommandText = "ALTER USER " +
storedAuth.UserName + " PASSWORD [" +
storedAuth.Password + "] []";
objOleDbCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
// Displaying any errors that
// might have occured.
MessageBox.Show("Error: " + ex.Message);
}
finally
{
objOleDbConnection.Close();
}
Cannot open the MS Office Access database engine workgroup information file
- When I have code as posted.
What I am trying to do in my code is to create MS Access 2007 file and then set the user name and password to it from my program. What am I doing wrong here?
Error occurs here: objOleDbConnection.Open();
EDIT: I have made some changes, seems like it opens a connection but the command is incorrect.
Now problem is here:
objOleDbCommand.CommandText =
"ALTER USER " + storedAuth.UserName +
" PASSWORD [" + storedAuth.Password + "] []";
The entire code:
// Creating an object allowing me connecting to the database.
OleDbConnection objOleDbConnection = new OleDbConnection();
objOleDbConnection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" +
"Data Source=" + sfdNewFile.FileName + ";Persist Security Info=False";
// Creating command object.
OleDbCommand objOleDbCommand = new OleDbCommand();
objOleDbCommand.Connection = objOleDbConnection;
try
{
objOleDbConnection.Open();
objOleDbCommand.CommandText = "ALTER USER " +
storedAuth.UserName + " PASSWORD [" +
storedAuth.Password + "] []";
objOleDbCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
// Displaying any errors that
// might have occured.
MessageBox.Show("Error: " + ex.Message);
}
finally
{
objOleDbConnection.Close();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要更改 Access DB 密码,必须以独占模式打开它。尝试将其添加到您的连接字符串中;Exclusive=1。
To change an Access DB password, you must it open in exclusive mode. Try adding this to your connection string ;Exclusive=1.
好吧,您收到的错误表明其他人正在使文件保持打开状态,这会阻止密码更改......
Well, the error you are getting suggests someone else is keeping the file open, which prevents the password change...
HelpNeeder,我认为您遇到的问题应该首先在您的其他问题中解决:
错误告诉我我还没有没有关闭连接,但不是吗?
谢谢!
HelpNeeder, I think the problems you are experiencing should first be solved in your other question:
Error tells me I haven't close the connection, but haven't I?
Thanks!