开发者

OleDbConnection s FillSchema doesn't change after alter table (Oracle)

开发者 https://www.devze.com 2023-01-16 08:17 出处:网络
I got a problem when using OleDbConnection in combination with an oracle Database. When i request the schema of an existing Table using the OleDbConnection\'s FillSchema Method the result seems to get

I got a problem when using OleDbConnection in combination with an oracle Database. When i request the schema of an existing Table using the OleDbConnection's FillSchema Method the result seems to get cached somehow.

To reproduce the Problem you need to do the followin steps:

create a table named cachetest with one column Request a schema of the table cachetest in your code via FillSchema Change the table by adding a column via alter table cachetest add column2 char(3) request the schema of cachetest again. The Schema doesn't contain the column2

OleDbConnection connection = new OleD开发者_如何学编程bConnection(
"Provider=" + "OraOLEDB.Oracle;" 
+"Data Source=" + "datasource" 
+ ";User Id=" + "msp" + ";" 
+ "Password=" + "msp" 
+";ChunkSize=1;" +  "OLEDB.NET=" + "true;");

connection.Open();
DataTable dt = new DataTable("cachetest");

OleDbDataAdapter adapter_oledb = 
         new OleDbDataAdapter("select * from cachetest", connection);

adapter_oledb.FillSchema(dt, SchemaType.Source);

int columncount1 = dt.Columns.Count;

OleDbCommand command = new OleDbCommand("alter table cachetest add column2  char(30)", connection);
 command.ExecuteNonQuery();

 connection.Close();
 OleDbConnection connection2 = new OleDbConnection(
"Provider=" + "OraOLEDB.Oracle;" 
+"Data Source=" + "datasource" 
+ ";User Id=" + "msp" + ";" 
+ "Password=" + "msp" 
+";ChunkSize=1;" +  "OLEDB.NET=" + "true;");

 DataTable dt2 = new DataTable("cachetest");
 connection2.Open();
 OleDbDataAdapter adapter_oledb2 = new OleDbDataAdapter(
        "select * from cachetest", connection2);

 adapter_oledb2.FillSchema(dt2, SchemaType.Source);

 int columncount2 = dt2.Columns.Count;

This Problem doesn't appear using a SQL server...

Do you have any Idea how to solve this problem?

best regards martin

0

精彩评论

暂无评论...
验证码 换一张
取 消