打开与 MS Access 2007 文件的连接时出错:无法打开 MS Office Access 数据库引擎工作组信息文件

发布于 2024-12-17 19:50:32 字数 1373 浏览 2 评论 0原文

无法打开 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

手长情犹 2024-12-24 19:50:32

要更改 Access DB 密码,必须以独占模式打开它。尝试将其添加到您的连接字符串中;Exclusive=1。

createMSFile.Create("Provider=Microsoft.ACE.OLEDB.12.0;Exclusive=1;Data Source=" +
        sfdNewFile.FileName);

To change an Access DB password, you must it open in exclusive mode. Try adding this to your connection string ;Exclusive=1.

createMSFile.Create("Provider=Microsoft.ACE.OLEDB.12.0;Exclusive=1;Data Source=" +
        sfdNewFile.FileName);
挽清梦 2024-12-24 19:50:32

好吧,您收到的错误表明其他人正在使文件保持打开状态,这会阻止密码更改......

Well, the error you are getting suggests someone else is keeping the file open, which prevents the password change...

酷遇一生 2024-12-24 19:50:32

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文