F
Frank
Hi,
imagine there's a WEB application reading data from an Oracle database
to visualize in using DataGrids in the clients browser. Yes, sounds
simple, just create OracleConnection + OracleCommand + DataAdapter,
bind a DataGrid to the DataAdapter, that's it.
Problem with that approach might be the hardcoded CommandString of the
OracleCommand. Whenever somebody requests query string changes you have
to adapt the C# code, to recompile and test your application, and last
but not least to deploy the new version to one or more servers.
To solve that the decision was made to create a StoredProcedure
containing the SQL CommandString, in case of query to be changed the
procedure independently from the C# application may be adapted.
Allright, after creating the StoredProcedure I adapted the C# code, so
that instead of the priviously used hardcoded query string of type
CommandType.Text the corresponding stored procedure of type
CommandType.StoredProcedure will be called. The procedure itself
supports a ReferenceCursor, which I bound to the return DataTable. No
big deal, in general it works.
BUT - THE PERFORMANCE:
Where the Text query took approx. 10s, the StoredProcedure took up to 2
minutes to return as the same data!
Does anybody have an idea what might be the reason for that behaviour?
Really appreciate your help - Frank
PS: Finaly two snapshots of the code, first the fast hardcoded version,
second the stored procedure based one:
[OLD]
dwhConnection.ConnectionString=(String)getSessionObject("dwhConnectionString");
generalDataAdapter.SelectCommand.CommandText= "SELECT * FROM MYTABLE";
DataTable dataGridInputTable=new DataTable("general");
generalDataAdapter.Fill(dataGridInputTable);
generalAdapter.Fill(dataGridInputTable);
[NEW]
OracleConnection oraConnection=new
OracleConnection((String)getSessionObject("oraConnectionString"));
OracleCommand generalQuery=new
OracleCommand("expt.expt_reports_pkg.getAllExperiments",
oraConnection);
generalQuery.CommandType=CommandType.StoredProcedure;
generalQuery.Parameters.Clear();
generalQuery.Parameters.Add(new OracleParameter("M_CURSOR",
OracleType.Cursor));
generalQuery.Parameters["M_CURSOR"].Direction=ParameterDirection.Output;
OracleDataAdapter currentAdapter=new OracleDataAdapter(generalQuery);
DataTable dataGridInputTable=new DataTable("general");
currentAdapter.Fill(dataGridInputTable);
imagine there's a WEB application reading data from an Oracle database
to visualize in using DataGrids in the clients browser. Yes, sounds
simple, just create OracleConnection + OracleCommand + DataAdapter,
bind a DataGrid to the DataAdapter, that's it.
Problem with that approach might be the hardcoded CommandString of the
OracleCommand. Whenever somebody requests query string changes you have
to adapt the C# code, to recompile and test your application, and last
but not least to deploy the new version to one or more servers.
To solve that the decision was made to create a StoredProcedure
containing the SQL CommandString, in case of query to be changed the
procedure independently from the C# application may be adapted.
Allright, after creating the StoredProcedure I adapted the C# code, so
that instead of the priviously used hardcoded query string of type
CommandType.Text the corresponding stored procedure of type
CommandType.StoredProcedure will be called. The procedure itself
supports a ReferenceCursor, which I bound to the return DataTable. No
big deal, in general it works.
BUT - THE PERFORMANCE:
Where the Text query took approx. 10s, the StoredProcedure took up to 2
minutes to return as the same data!
Does anybody have an idea what might be the reason for that behaviour?
Really appreciate your help - Frank
PS: Finaly two snapshots of the code, first the fast hardcoded version,
second the stored procedure based one:
[OLD]
dwhConnection.ConnectionString=(String)getSessionObject("dwhConnectionString");
generalDataAdapter.SelectCommand.CommandText= "SELECT * FROM MYTABLE";
DataTable dataGridInputTable=new DataTable("general");
generalDataAdapter.Fill(dataGridInputTable);
generalAdapter.Fill(dataGridInputTable);
[NEW]
OracleConnection oraConnection=new
OracleConnection((String)getSessionObject("oraConnectionString"));
OracleCommand generalQuery=new
OracleCommand("expt.expt_reports_pkg.getAllExperiments",
oraConnection);
generalQuery.CommandType=CommandType.StoredProcedure;
generalQuery.Parameters.Clear();
generalQuery.Parameters.Add(new OracleParameter("M_CURSOR",
OracleType.Cursor));
generalQuery.Parameters["M_CURSOR"].Direction=ParameterDirection.Output;
OracleDataAdapter currentAdapter=new OracleDataAdapter(generalQuery);
DataTable dataGridInputTable=new DataTable("general");
currentAdapter.Fill(dataGridInputTable);