在我的代码中,“无法找到可安装的ISAM”错误的原因是什么?

时间:2011-12-12 12:55:41

标签: c# winforms ms-access-2007

我无法弄清楚为什么我在这里收到错误说:Could not find installable ISAM。我正在尝试将数据添加到似乎有问题的Access文件中。

我不确定为什么这不起作用,因为我在删除每个条目时使用的是严格的严格代码。

这里有没有明显的错误?

        // Creating a query for each type of data.
        string sqlPC = @"INSERT INTO PersonalData([Type], [UserName], [Password]) 
                         VALUES(@Type, @UserName, @Password)";
        string sqlWS = @"INSERT INTO PersonalData([Type], [URL], [UserName], [Password]) 
                         VALUES(@Type, @URL, @UserName, @Password)";
        string sqlSC = @"INSERT INTO PersonalData([Type], [SoftwareName], [SerialCode]) 
                         VALUES(@Type, @SoftwareName, @SerialCode)";

    HashPhrase hashPhrase = new HashPhrase();
    Security security = new Security();

    private void InsertData(string sql)
    {
        string hashShortPass = hashPhrase.ShortHash(pass);

        string connectionString = 
            @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source={0};
              Persist Security Info=False; Jet OLEDB: Database Password={1};";

        using (OleDbConnection connection = new OleDbConnection())
        {
            connection.ConnectionString = 
                string.Format(connectionString, filePath, hashShortPass);

            using (OleDbCommand command = new OleDbCommand(sql, connection))
            {
                OleDbParameter prmType = new OleDbParameter
                    ("@Type", security.EncryptAES(cmbType.Text, pass, user));

                command.Parameters.Add(prmType);

                if (cmbType.SelectedIndex == 0)
                {
                    OleDbParameter prmUserName = new OleDbParameter
                        ("@UserName", security.EncryptAES
                            (txtUserName.Text.Trim(), pass, user));
                    OleDbParameter prmPassword = new OleDbParameter
                        ("@Password", security.EncryptAES
                            (txtPassword.Text, pass, user));

                    command.Parameters.Add(prmUserName);
                    command.Parameters.Add(prmPassword);
                }
                else if (cmbType.SelectedIndex == 1)
                {
                    OleDbParameter prmURL = new OleDbParameter
                        ("@URL", security.EncryptAES
                            (txtURL.Text.Trim(), pass, user));
                    OleDbParameter prmUserName = new OleDbParameter
                        ("@UserName", security.EncryptAES
                            (txtUserName.Text.Trim(), pass, user));
                    OleDbParameter prmPassword = new OleDbParameter
                        ("@Password", security.EncryptAES
                            (txtPassword.Text, pass, user));

                    command.Parameters.Add(prmURL);
                    command.Parameters.Add(prmUserName);
                    command.Parameters.Add(prmPassword);
                }
                else if (cmbType.SelectedIndex == 2)
                {
                    OleDbParameter prmSoftwareName = new OleDbParameter
                        ("@SoftwareName", security.EncryptAES
                            (txtSoftwareName.Text.Trim(), pass, user));
                    OleDbParameter prmSerialCode = new OleDbParameter
                        ("@SerialCode", security.EncryptAES
                            (txtSerialCode.Text.Trim(), pass, user));

                    command.Parameters.Add(prmSoftwareName);
                    command.Parameters.Add(prmSerialCode);
                }

                try
                {
                    connection.Open();
                    command.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message);
                }
            }
        }
    }

4 个答案:

答案 0 :(得分:3)

在我的情况下,我修正了:

我改变了:

string conexion = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\temp\Fa.mdb;Database Password=xxx;";

为:

string conexion = @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\temp\Fa.mdb;Persist Security Info=False; Jet OLEDB:Database Password='xxx';";

答案 1 :(得分:2)

我改变了:

string connectionString = 
            @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source={0};
              Persist Security Info=False; Jet OLEDB: Database Password={1};";

要:

string connectionString = 
            @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source={0};
              Persist Security Info=False; Jet OLEDB:Database Password={1};";

它有效,我有一个不需要的空间......

答案 2 :(得分:0)

对于插入部分,您有一个名为Password的字段,它是MS Access中的关键字。您的插入语句应包括[密码]而不是密码。

答案 3 :(得分:0)

在我的情况下我改变了

"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\\Export.accdb;Database Password=123"

作为

"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\\Export.accdb;Jet OLEDB:Database Password=123"

它有效......