Connecting Tech Pros Worldwide Help | Site Map

ODP.NET OracleCommand.CommandText conversion error

Newbie
 
Join Date: Aug 2009
Posts: 6
#1: Sep 21 '09
I am running the following lines...

Expand|Select|Wrap|Line Numbers
  1.             OracleConnection connection=new OracleConnection("myConnectionStringIsHere");
  2.             connection.Open();
  3.             var startValueParameter=new OracleParameter {ParameterName="@START_VALUE", Value=0};
  4.             var chunkSizeParameter=new OracleParameter {ParameterName="@CHUNK_SIZE", Value=10};
  5.             var command=new OracleCommand
  6.                             {
  7.                                 Connection=connection,
  8.                                 CommandType=CommandType.Text
  9.                             };
  10.                 command.CommandText = "select EmployeeID, test_id from ExampleTable where (test_id > :START_VALUE) AND (rownum <= :CHUNK_SIZE)";

The error I get is on the very last line where I try to set command.CommandText.

System.InvalidCastException: Unable to cast object of type 'System.String' to type 'Oracle.DataAccess.Client.OracleConnection'

This is very strange, as it suddenly started happening out of the blue. Any suggestions? Thanks.
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,148
#2: Sep 21 '09

re: ODP.NET OracleCommand.CommandText conversion error


Is the colorization of the text abnormal in your visual studio? If one of those quotes is not closed, it could be trying to interpret a whole section of your code as a connection string.

Is this not c#? Because "var" isn't a normal object type in C#. Are you getting mixed up with javascript?
Newbie
 
Join Date: Aug 2009
Posts: 6
#3: Sep 21 '09

re: ODP.NET OracleCommand.CommandText conversion error


'var' is new to C# 3.0
http://msdn.microsoft.com/en-us/library/bb383973.aspx

Also, it is not including anything abnormal in the connectionstring or the commandtext. All quotes are accounted for.
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,148
#4: Sep 22 '09

re: ODP.NET OracleCommand.CommandText conversion error


Quote:

Originally Posted by pieps86 View Post

'var' is new to C# 3.0
http://msdn.microsoft.com/en-us/library/bb383973.aspx

I thought of that after I had posted.
Hmm and you have debug stepped through to make sure nothing is mangling your objects?
Newbie
 
Join Date: Aug 2009
Posts: 6
#5: Sep 22 '09

re: ODP.NET OracleCommand.CommandText conversion error


Nope, nothing is getting skewed anywhere along the way. I even compared this code with older versions in Team Explorer to see if I could find anything that had been changed recently that would cause this error. Also, the problem only seems to be when I debug the project from within Visual Studio. I can put the DLL with this code in an engine and it runs fine.
ssnaik84's Avatar
Member
 
Join Date: Aug 2009
Location: Bengaluru, India
Posts: 119
#6: Sep 22 '09

re: ODP.NET OracleCommand.CommandText conversion error


"var" is introduced for LINQ and you can use it in case of lazy binding; where you dont know the data type at compile time.
if you will use it, application will run.. but you cant debug...
Newbie
 
Join Date: Aug 2009
Posts: 6
#7: Sep 23 '09

re: ODP.NET OracleCommand.CommandText conversion error


I don't know about that. I am, in fact, debugging to get this error. Using the 'var' keyword is not the issue. I can explicitly declare all types and still get the same result. Nonetheless, using 'var' does not prevent debugging. I'm in VS2008, btw.
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,148
#8: Sep 23 '09

re: ODP.NET OracleCommand.CommandText conversion error


So the error ONLY comes up in debugging, and not in a regular release?
That is very strange. Only thing I can think of is if you are pulling and values from the Properties section, they will be different between regular and debug runs.
Reply

Tags
c-sharp, commandtype, odp.net, oracle, oraclecommand