Re: Oracle vs MSSQL Parameters
- From: "Howard Hoffman" <HowardH@xxxxxxxxxxxxxxxx>
- Date: Mon, 5 Dec 2005 11:12:50 -0500
Adam
I'm kind of in your shoes. I'm bulding something that has to support
multiple databases. My SQL (stored procedures) is
(going to be) ported between those databases.
Have you looked at the DbCommandBuilder in System.Data.Common?
Each DbCommandBuilder leaf has a public static 'DeriveParameters' method.
You give the method an instance of a DbCommand (i.e. SqlCommand,
OracleCommand, etc.) and a live connection. The instance of the DbCommand
you give it need only have the CommandText / CommandType properties set.
Upon return from DeriveParameters, the DbCommand instance you passed will
have its Parameters collection filled out -- with names (database
specific!), types and a default value.
You can then just access your parameter (note that the 'name' of each
Parameter will have the DB-specific prefix -- @ or : or whatever) from the
collection and go from there.
Unless you can afford to make 2 round trips to the database for each call
(stored procedure, dynamic SQL, etc.), people tend to use the output of
DeriveParameters to generate code that you then use in your application in
production.
I believe CodeSmith tries to do this (though I'm not sure if its supports
Oracle directly); the MS Data Set Generator tool used in the VS.NET IDE also
does this.
HTH,
Howard Hoffman
"Adam Clauss" <cabadam@xxxxxxxx> wrote in message
news:11p0q8ke7lgpu93@xxxxxxxxxxxxxxxxxxxxx
> So, we originally wrote our application to use Oracle. As such, we used
> specifically declared OracleConnection and use ":" for naming parameters.
>
> Ex:
> SELECT * FROM sometable where somefield = :fieldValue
>
> Now, we have a need to port the code to SQL server for another client.
> I'm thinking we should do this the "right" way this time, and abstract
> things back to IDbConnection rather than OracleConnection or
> SqlConnection. Then, we can simply change what type of objects get
> created, and not the declarations of usage.
>
> This is good.
>
> What is bad is parameters - Oracle parameters begin wtih ":" whereas SQL
> server requires them to be "@". But there does not seem to be a "generic"
> way of handling this if we were to abstract back to the interfaces and
> have the SQL be compatible with different types of servers. Am I missing
> a way to do this?
>
> Thanks!
>
> --
> Adam Clauss
>
>
>
.
- References:
- Oracle vs MSSQL Parameters
- From: Adam Clauss
- Oracle vs MSSQL Parameters
- Prev by Date: Deadlocks during SqlDataReader.Read method
- Next by Date: OdbDataReader.GetSchemaTable and SQL Server 2005 XML Data Type
- Previous by thread: Re: Oracle vs MSSQL Parameters
- Next by thread: Re: DataAdapter Mapping only works for the first two tables.
- Index(es):
Relevant Pages
|
Loading