ODP.NET OracleCommand.CommandText conversion error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pieps86
    New Member
    • Aug 2009
    • 6

    ODP.NET OracleCommand.CommandText conversion error

    I am running the following lines...

    Code:
                OracleConnection connection=new OracleConnection("myConnectionStringIsHere");
                connection.Open();
                var startValueParameter=new OracleParameter {ParameterName="@START_VALUE", Value=0};
                var chunkSizeParameter=new OracleParameter {ParameterName="@CHUNK_SIZE", Value=10};
                var command=new OracleCommand
                                {
                                    Connection=connection,
                                    CommandType=CommandType.Text
                                };
                    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.Command Text.

    System.InvalidC astException: Unable to cast object of type 'System.String' to type 'Oracle.DataAcc ess.Client.Orac leConnection'

    This is very strange, as it suddenly started happening out of the blue. Any suggestions? Thanks.
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    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?

    Comment

    • pieps86
      New Member
      • Aug 2009
      • 6

      #3
      C# var

      'var' is new to C# 3.0
      Declaration statements introduce a new local variable, local constant, or local reference variable (ref local). Local variables can be explicitly or implicitly typed. A declaration statement can also include initialization of a variable's value.


      Also, it is not including anything abnormal in the connectionstrin g or the commandtext. All quotes are accounted for.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Originally posted by pieps86
        'var' is new to C# 3.0
        Declaration statements introduce a new local variable, local constant, or local reference variable (ref local). Local variables can be explicitly or implicitly typed. A declaration statement can also include initialization of a variable's value.
        I thought of that after I had posted.
        Hmm and you have debug stepped through to make sure nothing is mangling your objects?

        Comment

        • pieps86
          New Member
          • Aug 2009
          • 6

          #5
          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.

          Comment

          • ssnaik84
            New Member
            • Aug 2009
            • 149

            #6
            "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...

            Comment

            • pieps86
              New Member
              • Aug 2009
              • 6

              #7
              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.

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                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.

                Comment

                Working...