DB_SEC_E_AUTH_FAILED(0x80040E4D)C#无法多次打开数据库

时间:2017-05-03 15:30:19

标签: c# ms-access

好吧,我已经挣扎了这么久。我无法再次访问我的数据库(Access)。请帮忙。该错误在Search()方法中给出

namespace OEFEN
{
public partial class Form1 : Form
{
    public string DBFile;
    public OleDbConnection myDB;
    public string conn = @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=";
    public string searchString;
    public Form1()
    {
        InitializeComponent();
    }

    private void openDBToolStripMenuItem_Click(object sender, EventArgs e)
    {
        if (openFileDialog1.ShowDialog() == DialogResult.OK)
        {
            DBFile = openFileDialog1.FileName;
        }
    }

    private void exitToolStripMenuItem_Click(object sender, EventArgs e)
    {
        Application.Exit();
    }

    private void listToolStripMenuItem_Click(object sender, EventArgs e)
    {
        myDB = new OleDbConnection(conn+DBFile);
        myDB.Open();

        OleDbDataAdapter myDB_Adapter = new OleDbDataAdapter(@"SELECT * FROM Students ", myDB);
        DataSet ds = new DataSet();
        myDB_Adapter.Fill(ds, "Students");
        dataGridView1.DataSource = ds;
        dataGridView1.DataMember="Students";
        myDB.Close();
    }

    private void searchToolStripMenuItem_Click(object sender, EventArgs e)
    {
        Form3 iets = new Form3();

        iets.StartPosition = FormStartPosition.CenterScreen;
        iets.Show();

    }

    public void Search()
    {

        myDB = new OleDbConnection(conn+DBFile);
        myDB.Open();

        OleDbDataAdapter anderAdapter = new OleDbDataAdapter(@"SELECT * FROM Students WHERE st_Surname=" + searchString, myDB);
        DataSet kk = new DataSet();
        anderAdapter.Fill(kk, "List");
        dataGridView1.DataSource = kk;
        dataGridView1.DataMember = "List";
        myDB.Close();
    }
}

}

0 个答案:

没有答案