Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to force OracleCommand.BindByName to be true by default for ODP.NET?

Since the System.Data.OracleClient library has been deprecated, we are in the process of migrating our code base to use Oracle Data Provider for .NET (ODP.NET) instead. One of the issues that we have encountered is that the System.Data.OracleClient uses parameter name binding as opposed to binding by position and all of the code directly access the System.Data.OracleClient.OracleCommand as opposed to using an intermediate data layer.

Since there is quite a bit of code, is there an easy way to force the ODP.NET OracleCommand.BindByName to be true by default, or must we go through and set the value each time that it is used? Failing at that, is there an easy way to insert that line of code in Visual Studio 2008?

like image 975
rjzii Avatar asked Feb 01 '10 15:02

rjzii


4 Answers

I didn't try it but,

I have seen something like

"cmd.GetType().GetProperty("BindByName").SetValue(cmd,true,null);" in PetaPoco.cs file.

Maybe it can help.

like image 182
deniz Avatar answered Nov 11 '22 01:11

deniz


I know this thread is old, but I had the same problem today and thought I would share my solution in case someone else had this problem. Since OracleCommand is sealed (which sucks), I created a new class that encapsulates the OracleCommand, setting the BindByName to true on instantiation. Here's part of the implementation:

public class DatabaseCommand
{
    private OracleCommand _command = null;

    public DatabaseCommand(string sql, OracleConnection connection)
    {
        _command = new OracleCommand(sql, connection)
        {
            BindByName = true
        };
    }

    public int ExecuteNonQuery()
    {
        return _command.ExecuteNonQuery();
    }

    // Rest of impl removed for brevity
}

Then all I had to do to cleanup the commands was do a search for OracleCommand and replace with DatabaseCommand and test.

like image 24
BrandonZeider Avatar answered Nov 11 '22 00:11

BrandonZeider


I had the same problem with SqlDataSource Update commands after porting ASPX code to Oracle.DataAcees.Client and solved it by changing OracleCommand.BindByName property in SqlDataSource OnUpdating handler like this:

protected void SqlDataSource_Updating(object sender, SqlDataSourceCommandEventArgs e)
{
    Oracle.DataAccess.Client.OracleCommand b_OracleCommand = 
                  (Oracle.DataAccess.Client.OracleCommand)e.Command;
    b_OracleCommand.BindByName = true;
}
like image 5
Bore Avatar answered Nov 11 '22 02:11

Bore


With Oracle.ManagedDataAccess.Client, you can configure in app.config:

<oracle.manageddataaccess.client>
<version number="*">
  <dataSources>
    <dataSource alias="SampleDataSource" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL))) " />
  </dataSources>
  <settings>
    <setting name="BindByName" value="True"/>
  </settings>
</version></oracle.manageddataaccess.client>
like image 4
Sadao Avatar answered Nov 11 '22 01:11

Sadao