Access2013和Windows之间的连接形式c#(oledb)

时间:2014-12-25 19:52:48

标签: c#

我需要帮助! 我想在microsoft access 2013和我的Windows窗体之间建立连接,它不起作用我不知道为什么,这是我的代码:

private void Form1_Load(object sender, EventArgs e)
    {
        OleDbConnection cnn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.15.0;Data Source= C:\\Users\\NIZAR\\Documents\\Visual Studio 2010\\Projects\\C#\\testConnBD1\\testConnBD1\\madb1.accdb");
        try
        {
            cnn.Open();

            MessageBox.Show("Connection Open ! ");
            cnn.Close();
        }
        catch
        {
            MessageBox.Show("Can not open connection ! ");
        }
    }

2 个答案:

答案 0 :(得分:1)

您可能需要Microsoft Access 2013 Runtime.

Microsoft Access 2013 Runtime使您可以将Access 2013应用程序分发给未在其计算机上安装完整版Access 2013的用户。

Microsoft Access 2007 = ACE 12; Microsoft Access 2010 = ACE 14; Microsoft Access 2013 = ACE 15

enter image description here

答案 1 :(得分:0)

EDIT1: 它解决了所有人我在文件名中犯了一个错误: EDIT2:正确的连接字符串是:

Provider=Microsoft.ACE.OLEDB.15.0;Data Source=@"C:\\Users\\%usename%\\{%pathToYourData%}\\{%databaseName.Extension%}"