我偶尔会在日志中看到这个例外:
12:27:38,504 [8] DEBUG - Inside GetRoles USER1
12:27:38,537 [8] ERROR - Error in method, "GetRoles" . User account that invoked error- USER1
System.Data.OleDb.OleDbException (0x80004005): SQL0401: Comparison operator = operands not compatible.
Cause . . . . . : The operands of comparison operator = are not compatible. -- Numeric operands are compatible with any other numeric operands and with character and graphic operands. -- Character operands are compatible with operands that are character, graphic, date, time, timestamp, or numeric. -- Date, time, and timestamp operands are compatible with character and graphic operands or with another operand of the same type. -- Graphic operands are compatible with graphic, character, date, time, timestamp, or numeric operands. -- Binary operands are compatible only with binary operands. -- Operands that are user-defined types can only be compared to operands that are the same exact type. -- DataLink and XML operands cannot be compared. Recovery . . . : Check the data types of all operands to see if the data types are compatible. If all the operands of the SQL statement are correct and a view is being accessed, then check the data types of all the operands in the view definition. Correct the errors. Try the request again.
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForMultpleResults(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
at Dashboard.DataAccessLayer.DAL.GetRoles() in DAL.cs:line 98
这是我的代码:
public List<string> GetRoles()
{
List<string> tempList = new List<string>();
OleDbConnection connection;
OleDbCommand command;
string sql = null;
sql = "SELECT ROLE FROM " + LibraryList.PROJ + ".ROLE where UPPER(USERID) = UPPER(?)";
using (connection = new OleDbConnection(_connectionString))
{
using (command = new OleDbCommand())
{
try
{
connection.Open();
command.Connection = connection;
command.Parameters.Add("@userID", OleDbType.Char, 10).Value = CurrentUser.getUserID();
log.Debug("Inside GetRoles " + CurrentUser.getUserID());
command.CommandText = sql;
using (OleDbDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
tempList.Add(reader.GetString(0));
}
}
}
catch (Exception ex)
{
log.Error("Error in method, \"GetRoles\" . User account that invoked error- " + CurrentUser.getCurrentUserDisplayInfoForLogging(), ex);
}
}
}
return tempList;
}
我打印出值,它是一个字符串,所以它不是null或空或任何东西。这种情况很少发生,因此当看起来价值与其他任何时间相同时,很难确定发生了什么,但有时却不喜欢它。
可能导致此问题的原因是什么?