我目前正在保存值以访问数据库,为此我使用了 Microsoft.Jet.OLEDB.4.0 提供程序,并且我在 Visual Studio 的项目中将平台模式从任何 cpu 配置为 x86,它在 x86 平台上运行良好,但是当我启动单元时使用 nunit 测试它不接受 x86 平台并且 nunit 显示错误
“UnitTest_Finance.Test.Class1.InsertCashPayment:System.InvalidOperationException:'Microsoft.Jet.OLEDB.4.0' 提供程序未在本地计算机上注册。”
现在我想要在使用 nunit 执行单元测试时用另一种方法来处理这个错误。
这是我的代码仅供参考
class RepairDLL
{
string dbConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/AutoRepairDB.mdb";
//Method to Booking Value
public virtual bool Insert_Data_Repair_History(EntityClass ec)
{
bool isInsert = false;
//Connect to Database
OleDbConnection connection = new OleDbConnection(dbConn);
connection.Open();
try
{
//Insert Customer Value
string sql = "INSERT into [Repair_History] (FirstName,LastName,City,State,VehicleNo,LienseNo,RepairDate,Summary,Charge) "
+ "VALUES ('" + ec.R_firstName + "','" + ec.R_lastName + "','" + ec.R_city + "','" + ec.R_state + "','" + ec.R_vehicleNo + "','" + ec.R_licenseNo + "','" + ec.R_date + "','" + ec.R_summary + "','" + ec.R_charge + "')";
OleDbCommand command = new OleDbCommand(sql, connection);
command.ExecuteNonQuery();
connection.Close();
isInsert = true;
}
catch
{
throw new Exception();
}
finally
{
// Close the connection
if (connection != null)
{
connection.Close();
}
}
return isInsert;
}
}