简体   繁体   中英

OracleBulkCopy error (table or view does not exist)

I'm trying to copy datatable from sql server to oracle using OracleBulk Copy. However I'm getting the following error:

ORA-00942: table or view does not exist

For the line orca_bulk_copy.WriteToServer(dt); .

The code is as follows:

string sqlstring = "select POSITION_ID, POSITION_DESC  from T_CD_POSITION";
SqlDataAdapter o_SQLDataAdaptor = new SqlDataAdapter(sqlstring, sqlconn);
DataTable dt = new DataTable();
o_SQLDataAdaptor.Fill(dt);

//SqlCommand scmd = new SqlCommand(sqlstring, sqlconn);
//SqlDataReader reader = scmd.ExecuteReader();

foreach (DataRow row in dt.Rows)
{
    OracleConnection oraconn = new OracleConnection(oradb);
    oraconn.Open();
    Console.WriteLine("orca conn established....");


    OracleBulkCopy orca_bulk_copy = new OracleBulkCopy(oraconn);

    orca_bulk_copy.DestinationTableName = "UHAMPTST.t_test_postion";
    orca_bulk_copy.BatchSize = 5000;
    orca_bulk_copy.BulkCopyTimeout = 10000;
    Console.WriteLine("hh");
    orca_bulk_copy.ColumnMappings.Add("position_id", "position_id");

    orca_bulk_copy.ColumnMappings.Add("position_desc", "position_desc");
    orca_bulk_copy.WriteToServer(dt); // <----- ORA-00942 error occurs here!!
    Console.WriteLine("hhdd");
    orca_bulk_copy.Close();
    orca_bulk_copy.Dispose();

I did try to find why this error is coming but did not get enough info on it.

ORA-00942 - Table does not exists error , one of the main error, any novice SQL developer faces. Please check the below.

1) When you don't refer a table with a SCHEMA name, check whether a PUBLIC SYNONYM exists for it. If it doesn't or you cannot have a public synonym, either you have to explicitly specify the schema name as a prefix to the table, else the USER_ID you used to connect to the database has default access to that schema.

2) Check whether, you have SELECT privileges from the table you try to select and INSERT/UPDATE privilege to the table you try to copy to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM