I’m getting an error message: unimplemented or unreasonable conversion requested using the following code:
OdbcConnection oConn = new OdbcConnection();
oConn.ConnectionString = @"Driver={Oracle ODBC Driver};Data Source=*****;UID=********;PWD=******;DBQ=*****;DBA=R;APA=T;FEN=T;QTO=F;FRC=10;FDL=10;LOB=F;RST=T;FRL=T;MTS=F;CSR=F;PFC=10;TLO=0;";
oConn.Open();
string user = "ANYUSER";
string family = "ANYFAMILY";
DateTime date = DateTime.Today;
OdbcCommand FindCases = new OdbcCommand(@"select TABLE_CASE.ID_NUMBER, TABLE_USER.LOGIN_NAME
from TABLE_CASE, TABLE_USER, TABLE_PRIVCLASS, TABLE_CONDITION, TABLE_PART_NUM
where TABLE_CASE.CASE_ORIGINATOR2USER=TABLE_USER.OBJID and TABLE_CASE.CASE_STATE2CONDITION=TABLE_CONDITION.OBJID and TABLE_CASE.CASE_PRT2PART_INFO=TABLE_PART_NUM.OBJID
and TABLE_USER.USER_ACCESS2PRIVCLASS=TABLE_PRIVCLASS.OBJID and TABLE_USER.LOGIN_NAME=? and TABLE_PART_NUM.FAMILY=? and TABLE_CONDITION.S_TITLE='CLOSED' and TABLE_CASE.CREATION_TIME > to_date(?,'MM/DD/YYYY HH:MI:SS AM')", oConn);
FindCases.CommandType = System.Data.CommandType.Text;
FindCases.Parameters.Add(@"user", OdbcType.Text, 4000).Value = user;
FindCases.Parameters.Add(@"family", OdbcType.Text, 4000).Value = family;
FindCases.Parameters.Add(@"date", OdbcType.DateTime, 4000).Value = date;
if (oConn.State == System.Data.ConnectionState.Open)
{
try
{
OdbcDataReader readCases = FindCases.ExecuteReader(); //errors at this line
I have looked around online and the only suggestion I could find was using a to_clob statement. Either I don’t understand how it works or that doesn’t fix the issue. To my knowledge there shouldn’t be any coversion of data types. The ‘user’ field is text, the ‘family’ field is text, and the ‘date’ field is DateTime in the database.
Any ideas are very apreciated!
UPDATE
This code works:
OdbcCommand FindCases = new OdbcCommand(@"select TABLE_CASE.ID_NUMBER, TABLE_USER.LOGIN_NAME
from TABLE_CASE, TABLE_USER, TABLE_PRIVCLASS, TABLE_CONDITION, TABLE_PART_NUM
where TABLE_CASE.CASE_ORIGINATOR2USER=TABLE_USER.OBJID and TABLE_CASE.CASE_STATE2CONDITION=TABLE_CONDITION.OBJID and TABLE_CASE.CASE_PRT2PART_INFO=TABLE_PART_NUM.OBJID
and TABLE_USER.USER_ACCESS2PRIVCLASS=TABLE_PRIVCLASS.OBJID and TABLE_USER.LOGIN_NAME=? and TABLE_PART_NUM.FAMILY='Desktop' and TABLE_CONDITION.S_TITLE='CLOSED' and TABLE_CASE.CREATION_TIME > ?", oConn);
FindCases.CommandType = System.Data.CommandType.Text;
FindCases.Parameters.Add(@"user", OdbcType.Text, 4000).Value = user;
//FindCases.Parameters.Add(@"family", OdbcType.Text, 4000).Value = family;
FindCases.Parameters.Add(@"date", OdbcType.DateTime, 4000).Value = date;
UPDATE (AGAIN)
This code also works perfectly although vulnerable to SQL injection.
OdbcCommand FindCases = new OdbcCommand(@"select TABLE_CASE.ID_NUMBER
from TABLE_CASE, TABLE_USER, TABLE_PRIVCLASS, TABLE_CONDITION, TABLE_PART_NUM
where TABLE_CASE.CASE_ORIGINATOR2USER=TABLE_USER.OBJID and TABLE_CASE.CASE_STATE2CONDITION=TABLE_CONDITION.OBJID and TABLE_CASE.CASE_PRT2PART_INFO=TABLE_PART_NUM.OBJID
and TABLE_USER.USER_ACCESS2PRIVCLASS=TABLE_PRIVCLASS.OBJID and TABLE_USER.LOGIN_NAME=? and TABLE_PART_NUM.FAMILY='" + family + "' and TABLE_CONDITION.S_TITLE='CLOSED' and TABLE_CASE.CREATION_TIME > ?", oConn);
FindCases.CommandType = System.Data.CommandType.Text;
FindCases.Parameters.Add(@"user", OdbcType.Text, 4000).Value = user; //field size 30, text
//FindCases.Parameters.Add(@"family", OdbcType.Text, 4000).Value = family; //field size 20, text
FindCases.Parameters.Add(@"date", OdbcType.DateTime, 4000).Value = date;
SOLUTION
I did not realize that ‘text’ wasn’t a true type. Changing to NVARCHAR did the trick:
OdbcCommand FindCases = new OdbcCommand(@"select TABLE_CASE.ID_NUMBER
from TABLE_CASE, TABLE_USER, TABLE_CONDITION, TABLE_PART_NUM
where TABLE_CASE.CASE_ORIGINATOR2USER=TABLE_USER.OBJID and TABLE_CASE.CASE_STATE2CONDITION=TABLE_CONDITION.OBJID and TABLE_CASE.CASE_PRT2PART_INFO=TABLE_PART_NUM.OBJID
and TABLE_USER.LOGIN_NAME=? and TABLE_PART_NUM.FAMILY=? and TABLE_CONDITION.S_TITLE='CLOSED' and TABLE_CASE.CREATION_TIME > ?", oConn);
FindCases.CommandType = System.Data.CommandType.Text;
FindCases.Parameters.Add(@"user", OdbcType.NVarChar, 30).Value = user; //field size 30, text
FindCases.Parameters.Add(@"family", OdbcType.NVarChar, 20).Value = family; //field size 20, text
FindCases.Parameters.Add(@"date", OdbcType.DateTime, 4000).Value = date;
Some questions, guesses and suggestions…
What is the exact DDL SQL type for
TABLE_PART_NUM.FAMILY?Did you try using
OdbcType.VarChar,OdbcType.NVarCharor evenOdbcType.NTextinstead ofOdbcType.Text?Also, please note that by default NVARCHAR2 size is in characters but VARCHAR2 is in bytes – maybe “4000” in your code is interpreted as 4000 characters, exceeding the maximal field width for character data of 4000 bytes. Try using 2000 or even lower number just for testing purposes.
Try to execute the query from the SQL Developer. Do you have any problems there?
Do you use any “unusual” character encoding in your database? You can execute…
…and look at
NLS_CHARACTERSETfor VARCHAR2 encoding andNLS_NCHAR_CHARACTERSETfor NVARCHAR2 encoding.What are the exact versions of your ODBC driver and Oracle server? Do they match?
Do you get this problem if you try using the equivalent ODP.NET code?