I am writing a C# program involves of an Oracle database using Oracle.DataAccess.Client -> OracleConnection
Though, I have a question about reusing the same connection to fetch data from the same database. Here's what I've done.
Code |
Then I use that connection to fetch data from the database into an OracleDataAdapter
Code |
Then I add a column into the database using the connection
Code |
Then I try to use the connection to fetch data again using OracleDataReader
Java |
But when I try to look for the new column that I found, it said the table doesn't have that new column I've just added, though it still has the old table structure. So I did many...many tests and found that:
1) If I use a new connection, I can fetch the newly added column (using select * from test)
2) Or I can fetch the newly added column using the old connection (using select FID from test), (select * from test) will not have the new column 'ID' that I've added
3) Or if I didn't fetch the data at the beginning (select * from test), I can fetch the newly added column after adding the table column (select * from test)
It seems like the memory hold on to the first data structure and giving the same stuff at the 2nd fetch, so I wonder why this is happening, is that a way that I can release the memory of the connection? This is just my guess-imate.
Can anyone explain why this is happening? Thanks!

Guest UserRank #1,422 · 1.2K reputationPosted Feb 17, 2011, 9:17 AM EST
Richard11 reputationPosted Feb 17, 2011, 9:22 AM EST
plus the 'alter' command should be auto commit during transaction.
Guest UserRank #1,422 · 1.2K reputationPosted Feb 18, 2011, 8:01 AM EST
Richard11 reputationPosted Feb 18, 2011, 8:38 AM EST
Richard11 reputationPosted Feb 25, 2011, 12:04 PM EST
I did more research and suspected it may be the statement caching in the connection string but give me the same result.
Mahesh ChandRank #1 · 393.3K reputationPosted Feb 25, 2011, 3:46 PM EST
Richard11 reputationPosted Feb 28, 2011, 4:19 AM EST
Mahesh ChandRank #1 · 393.3K reputationPosted Feb 28, 2011, 4:28 AM EST
Suthish NairRank #92 · 22.8K reputationPosted Feb 28, 2011, 5:08 AM EST
Its working for me..
New column get added.
Can also fetch the new column.
using System.Data.OracleClient;
string OracleConString = "Password=111;User id=1111;Data Source=hello;Connection Lifetime=0";
OracleConnection OracleCon = new OracleConnection(OracleConString);
OracleCon.Open();
OracleDataAdapter Adapter = new OracleDataAdapter();
Adapter.SelectCommand = new OracleCommand("select * from test1", OracleCon);
DataSet ds = new DataSet();
Adapter.Fill(ds);
string alterColSQL = "alter table test1 add ID number(11)";
OracleCommand alterCmd = new OracleCommand(alterColSQL, OracleCon);
alterCmd.ExecuteNonQuery();
string ReadSQL = "select * from test1";
OracleCommand ReadCmd = new OracleCommand(ReadSQL, OracleCon);
OracleDataReader GISReader = ReadCmd.ExecuteReader();
DataTable ReaderTable = new DataTable();
ReaderTable.Load(GISReader);
ds.Tables.Add(ReaderTable);
OracleCon.Close();
Richard11 reputationPosted Feb 28, 2011, 6:08 AM EST
string OracleConString = "User Id=user;Password=pass;Data Source=source;Statement Cache Size=0;Connection Lifetime=0";
DataSet ds_CvnDataset = new DataSet("ds_CvnDataset");
OdbcDataAdapter CvnAdapter = new OdbcDataAdapter();
DataTable dt_CvnData = new DataTable();
CvnAdapter.Fill(ds_CvnDataset, "ds_CvnDataset");
dt_CvnData = ds_CvnDataset.Tables["ds_CvnDataset"];
DataSet ds_CopyToGISSet = new DataSet("CopyToGISSet");
OracleDataAdapter CopyToGISAdapter = new OracleDataAdapter();
DataTable dt_CopyToGISTable = new DataTable();
OracleCommandBuilder CopyToGISBuilder = new OracleCommandBuilder(CopyToGISAdapter);
CopyToGISAdapter.SelectCommand = new OracleCommand("select * from pole_database_bk", OracleCon);
CopyToGISAdapter.Fill(ds_CopyToGISSet, "CopyToGISSet");
dt_CopyToGISTable = ds_CopyToGISSet.Tables["CopyToGISSet"];
string alterColSQL = "alter table pole_database_bk add FID number(11)";
OracleCommand alterCmd = new OracleCommand(alterColSQL, OracleCon);
alterCmd.ExecuteNonQuery();
string GISReadSQL = "select * from pole_database_bk";
OracleCommand GISReadCmd = new OracleCommand(GISReadSQL, OracleCon);
OracleDataReader GISReader = GISReadCmd.ExecuteReader();
DataTable GISReaderTable = new DataTable("GISReader");
GISReaderTable.Load(GISReader);
MPdataset.Tables.Add(GISReaderTable);
oDataGrid.SetDataBinding(MPdataset, "GISReader");
Suthish NairRank #92 · 22.8K reputationPosted Feb 28, 2011, 8:35 AM EST