You can’t do it like this.
I don’t know if it was a mistake (it seems not) or was purposeful, but the class OdbcConnection
does not derive from one that can be generalized. If it was purposeful then it must have a reason, even if not explicit (there are indications in the documentation), and it must be different even. It even derives from something too generic (Component
) which cannot be used here, it would have to be something more specific a little, see below.
Already the MySqlConnection
derives from DbConnection
that seems appropriate. If the other class derived from it too, and intuitively I think which should, but also has indications that it should not, so it would be easy to solve with a more generic type object, the DbConnection
.
But it doesn’t have that and it seems to have a good reason, so the right thing is not to generalize, it has to do everything separately even. They are completely different logics, it is not correct to try to join the two, however tempting.
ODBC has several limitations, works the connection in a different way and needs care that a normal connection does not need, so they probably made it different and did not derive from DbConnection
, that is, from what is in the documentation gives the idea that it is a mistake to do what you are trying to.
I’m not even getting into the merits if this is all right. Should we handle an ODBC database be used? Are you sure? This is quite complicated to work right, even more trying to use the same logic for him and for Mysql. Unless you’re not using the same logic, then it wouldn’t make sense to try to join the connection.
The solution seems to be different, but without a bigger context you can’t even begin to help. It seems to be a XY problem.
Not to mention that most of the codes, even simple, of connection that I see posted here have problems and unnecessary complications, I can not say that this is the case for the lack of context, but may have other problems, even the unnecessary use of ODBC.
And don’t use dynamic
to make a gambit. It may work, but it’s not right. This command was created for cases where you have no control over the composition of the object. In this case you have control. Less still start something with null
, almost in all cases this is a sign of error. It is creating a problem to fix the real problem. It is working by coincidence.
These functions I use take more than 50 fields of the table, The tables have the same structure only they are in different banks, make 1 function for each bank would q a modification in something need to be done in the 3 functions and would leave the code much bigger, so I used this solution.
– Andeton Feitosa
Not creating the right abstraction, that is, it is an XY problem.
– Maniero
I don’t believe this is considered an answer to people who are having the same problem, but since I can’t put the question as an answer I’ll mark yours to close the topic.
– Andeton Feitosa