Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

I'm trying to get my head around what's going wrong when I'm executing the below select statement in my asp.net MVC project.

C#
public static Vessel GetVesselDetails(string vesselId, string outbound, string callnumber)
        {
            var vessel = new Vessel {Id = vesselId};
            
            using (var connection = new OracleConnection(_connectionString))
            {
                const string query = @"SELECT * FROM OPS_REPORT.SHIP_VOYAGE WHERE SHIP_ID= :1 AND SHIP_VOYAGE.OUT_VOY_NBR= :2 AND SHIP_VOYAGE.OUT_CALL_NBR = :3";
                var command = new OracleCommand(query) { Connection = connection };
                
                command.Parameters.Add("1", OracleDbType.NVarchar2, 5).Value = vesselId;
                command.Parameters.Add("2", OracleDbType.NVarchar2, 5).Value = outbound;
                command.Parameters.Add("3", OracleDbType.NVarchar2, 5).Value = callnumber;

                try
                {
                    connection.Open();
                    OracleDataReader dr = command.ExecuteReader();
                    while (dr.Read())
                    {
                        vessel.Name = dr["NAME"].ToString();
                        vessel.LineOperator = dr["LINE_ID"].ToString();
                        vessel.Service = dr["SERVICE_ID"].ToString();
                    }

                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    if (connection.State != ConnectionState.Closed)
                    {
                        connection.Close();
                    }
                }
            }
            return vessel;
        }



The parameters passed trigger the below error, however they're doing this not consistently.
ORA-01460: unimplemented or unreasonable conversion


For example when I run the above with the following parameters, it runs without any issues.
C#
string vesselId = "DES";
string outbound = "16C1";
string callnumber = "1";


However the parameters change to the below, it returns the ORA-01460 exception...
C#
string vesselId = "CGVG";
string outbound = "078E";
string callnumber = "1";


Both select statements work perfectly when I execute them with the above values directly via Toad onto the database view. So that puzzles me even more.

I'm sure I'm overlooking something simple, or handling the parameter declaration in a way that's not recommended. Any pointers towards the right way are much appreciated.

What I have tried:

I have tried changing the way I set the parameters after browsing some information in regards to the ORA-01460 error message.

C#
command.Parameters.Add(new OracleParameter("1", vesselId));
command.Parameters.Add(new OracleParameter("2", outbound));
command.Parameters.Add(new OracleParameter("3", callnumber));


What happens than is that I get the error message when sending in both sets of parameters I described in the Problem summary above.

I checked the Datatypes on the tables as well, these are:
SHIP_ID -> VARCHAR2 (4 Byte)
OUT_VOY_NBR -> VARCHAR2 (5 Byte)
OUT_CALL_NBR -> VARCHAR2 (1 Byte)
All of them are not Nullable.
Posted
Updated 7-Jun-16 4:14am
v2
Comments
Richard Deeming 7-Jun-16 9:45am    
Have you tried specifying the correct type and size for the parameters?

command.Parameters.Add("1", OracleDbType.Varchar2, 4).Value = vesselId;
command.Parameters.Add("2", OracleDbType.Varchar2, 5).Value = outbound;
command.Parameters.Add("3", OracleDbType.Varchar2, 1).Value = callnumber;
Zephire 7-Jun-16 9:50am    
Hi Richard, I updated the parameters as suggested. Once updated it triggers the error on both examples given above.

1 solution

You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

Use the debugger to make sure everything is as expected, track all variables on each line until something unexpected append.
Your problem is data dependent, so one must be on server to track the root of problem.
If you can't debug, use Console.WriteLine as checkpoint to log what the code is doing with what values on variables.

[Update]
Quote:
ORA-01460: unimplemented or unreasonable conversion

Rather than using strings, I would rather try char arrays. Looks like Oracle is unable to convert the parameters it receive to the type it needs to process the query.
 
Share this answer
 
v2
Comments
Zephire 7-Jun-16 10:20am    
Hi ppolymorphe, I'm debugging the code while it runs following each line as it gets processed. All variables are assigned properly, there's nothing else going in apart from the variables I mentioned in the question.
The moment it handles the command.ExecuteReader method than it triggers an exception, as mentioned above that returns the ORA-01460 message.
Not sure where you'd assume I'm just guessing what my code is doing? As well as assuming that I'm not debugging this at all?
Patrice T 7-Jun-16 10:47am    
Nice to hear you use the debugger.
You would be surprised by the number of people that come here asking for help and that don't know about the debugger.
Zephire 8-Jun-16 6:03am    
Thanks for the suggestion, I've tried changing the parameters to char arrays as you suggested. The same issue pops up. On the first set of parameters no problem, on the second set again the ORA-01460 triggers as exception.

I'll keep digging to pinpoint the origin of this nasty error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900