I am upgrading an old VB project (before C#) from .NET 2 to 4.6.1
It is important to note that this project is agnostic when it comes to database providers. It uses SQL Server or Oracle merely by changing the connection string. Presumably, it will work against any other OleDB data source. It follows that direct references to Oracle binaries must be avoided. For example, what follows is using Oracle but I can't reference Oracle.anything in source code.
Here is my problem:
This snippet of code executes perfectly under .NET 2.0:
cmdDB.Transaction = transDB
cmdDB.CommandText = "myPackage.MyFunction"
cmdDB.CommandType = CommandType.StoredProcedure
cmdDB.Parameters.Add("p_extract_key", someValue)
cmdDB.Connection = conDB
Try
rdrDB = cmdDB.ExecuteReader(CommandBehavior.SingleRow)
Catch ex As Exception
Debug.WriteLine(ex.ToString)
Throw ex
End Try
```
Then it uses rdrDB to read the row
It compiles against 4.6.1 after changing "Parameters.Add" to "Parameters.AddValue"
However, it fails with "PLS-00306: wrong number or types of arguments in call to 'MyFunction'"
The signature of the stored procedure looks like this:
TYPE outcur_type is REF CURSOR;
procedure OBJEX_PR_OFFICE(p_extract_key in varchar2, outcur out outcur_type);
"outcur" is of type REF_CURSOR
Guessing that there has been a breaking change that now requires me to supply an OUT paramter for the cursor, I added these lines of code before Try:
Dim outCursor As New OleDbParameter
outCursor.ParameterName = "outcur"
outCursor.Direction = ParameterDirection.Output
cmdDB.Parameters.Add(outCursor)
And now we get this:
Exception thrown: 'System.InvalidOperationException' in System.Data.dll
System.InvalidOperationException: String[1]: the Size property has an invalid size of 0.
at System.Data.OleDb.OleDbParameter.BindParameter(Int32 index, Bindings bindings)
at System.Data.OleDb.OleDbCommand.CreateAccessor()
at System.Data.OleDb.OleDbCommand.InitializeCommand(CommandBehavior behavior, Boolean throwifnotsupported)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
I have spent several hours tring various combinations of parameter values. It appears to me that setting the outCursor parameter's DbType to type DbType.Cursor or OleDBType.Cursor might help but no types like that seem to exist.
I could alter the app to define an interface and create implementations for different database providers and avoid OleDB. But before I inform my client that the cost of their project is about to explode, I thought I would ask the community for ideas.
Any thoughts regarding what to do next?