An exception was thrown after using a transaction during Oraclebulkcopy bulk data import.
You can import batches correctly when you are not using transactions.
ORA-12154: Unable to resolve the specified connection string.
But the TNS configuration is certainly not wrong,
Is it not connectionstring that the execution of the transaction has changed,
And also:
Temporarily discovers that Oracle's bulkcopy does not support transactional processing
using (oraclebulkcopy bulkcopy = new Oraclebulkcopy (conn,oraclebulkcopyoptions.useinternaltransaction))
If the transaction is not supported, this oraclebulkcopyoptions.useinternaltransaction how to explain.
1 Private voidButton2_Click (Objectsender, EventArgs e)2 {3OpenFileDialog afd =NewOpenFileDialog ();4 if(AfD. ShowDialog ()! =System.Windows.Forms.DialogResult.OK)5 {6 return;7 }8 stringFileName =AfD. FileName;9 if(Path.getextension (fileName)! =". csv")Ten { OneMessageBox.Show ("the file name suffix must be a. csv"); A return; - } -DataTable table =NewDataTable (); the using(Stream stream =NewFileStream (FileName, FileMode.Open, FileAccess.Read)) - using(StreamReader sr =NewStreamReader (Stream, Encoding.default)) - { - stringFirstline =Sr. ReadLine (); + stringLine ; - + A #regionAdd the Created column to the table's column collection at //Id -DataColumn column =NewDataColumn (); -Column. ColumnName ="Id"; -Column. DataType = System.Type.GetType ("System.Int32"); - table. Columns.Add (column); - //Mobilenumber inColumn =NewDataColumn (); -Column. ColumnName ="Mobilenumber"; toColumn. DataType = System.Type.GetType ("System.String"); +Column. MaxLength =Ten; - table. Columns.Add (column); the //Mobilearea *Column =NewDataColumn (); $Column. ColumnName ="Mobilearea";Panax NotoginsengColumn. DataType = System.Type.GetType ("System.String"); -Column. MaxLength = -; the table. Columns.Add (column); + //Mobiletype AColumn =NewDataColumn (); theColumn. ColumnName ="Mobiletype"; +Column. DataType = System.Type.GetType ("System.String"); -Column. MaxLength = -; $ table. Columns.Add (column); $ //AreaCode -Column =NewDataColumn (); -Column. ColumnName ="AreaCode"; theColumn. DataType = System.Type.GetType ("System.String"); -Column. MaxLength =Ten;Wuyi table. Columns.Add (column); the //Postcode -Column =NewDataColumn (); WuColumn. ColumnName ="Postcode"; -Column. DataType = System.Type.GetType ("System.String"); AboutColumn. MaxLength =8; $ table. Columns.Add (column); - #endregion - - while(line = Sr. ReadLine ())! =NULL) A { + string[] mobilemsg = line. Split (New Char[] {','}, stringsplitoptions.removeemptyentries); the intId = Convert.ToInt32 (mobilemsg[0]); - stringMobilenumber = mobilemsg[1]. Trim ('"'); $ stringMobilearea = mobilemsg[2]. Trim ('"'); the stringMobiletype = mobilemsg[3]. Trim ('"'); the stringAreaCode = mobilemsg[4]. Trim ('"'); the stringPostcode = mobilemsg[5]. Trim ('"'); the //Create rows, add rows to the rows in the table collection -DataRow row =table. NewRow (); inrow["Id"] =Id; therow["Mobilenumber"] =Mobilenumber; therow["Mobilearea"] =Mobilearea; Aboutrow["Mobiletype"] =Mobiletype; therow["AreaCode"] =AreaCode; therow["Postcode"] =postcode; the table. Rows.Add (row); + } - } the Bayi inti =table. Rows.Count; theStopwatch SW =NewStopwatch (); the SW. Start (); - using(OracleConnection conn =NewOracleConnection ())//Connection - { theConn. ConnectionString =@"Data source= (DESCRIPTION = the (address_list = the (ADDRESS = (PROTOCOL = TCP) (HOST = 192.168.1.117) (PORT = 1521)) the ) - (Connect_data = the (SERVER = dedicated) the (service_name = orcl.192.168.1.117) the ))94 ); User Id=scott; password=abcd5226584;"; the Conn. Open (); the using(OracleTransaction tx = conn. BeginTransaction ())//Start a transaction the using(Oraclebulkcopy bulkcopy =Neworaclebulkcopy (conn,oraclebulkcopyoptions.useinternaltransaction))98 { AboutBulkcopy.destinationtablename ="T_mobile"; - foreach(DataColumn columninchtable. Columns)101 {102BULKCOPY.COLUMNMAPPINGS.ADD (column. ColumnName, column. ColumnName);//source column name, target column name103 }104 Try //Roll Back If an exception occurs the {106Bulkcopy.writetoserver (table);//writing table tables to database tables107 tx.commit ();108 }109 Catch(Exception ex) the {111 TX. Rollback (); the Throw NewException (ex. Message);113 } the } the SW. Stop (); theMessageBox.Show ("time consuming:"+ SW. Elapsedmilliseconds +"seconds");117 }118 }119}
error code: oraclebulkcopy for transaction processing
Oracle's oraclebulkcopy does not support transactional processing