Doing database backup and restore.
I used odp.net to return the data table directly to the dataset using the stored procedure +oracledataadapter, but prompted "invalid conversion specified". I wonder why the report application and query, do not report this error, and export the physical table, the report this error.
Check the information to find out why:
The OracleDataAdapter class attempts to maps Oracle native data types to. NET Data types
Number, DATE, TIMESTAMP, TIMESTAMP with the LOCAL time zone, TIMESTAMP with time zone, INTERVAL day to SECOND
Some of the above types may cause exceptions due to database accuracy and. NET precision. For example, the database number is 38 bits, but Decemal is only 28 bits.
Oracle decided, the best-of-the-these types of data in a Dataset object without losing any detail would be eithe R as a byte array or a string
Oracel recommended user manually define this mapping!
_myadapter.safemapping.add ("Launchdate", typeof (String)); _myadapter.safemapping.add ("Expirydate", typeof (Byte[]));
So many tables, how do I know which column has the wrong accuracy? All my data is of type number. So I wrote a piece of code,
Use OracleDataReader to loop through the columns to find the problem column!
Oracledatareader reader = cmd. ExecuteReader (); Int x = 0;do{ trace.writeline ("Table" + (++x)); while (reader. Read ()) { string result = reader. GetString (3) + "-" + reader. GetString (4) + "+"; for (int j = 6; j < reader. fieldcount - 1; j++) { try { if (!reader. IsDBNull (j) && reader. GetFieldType (j) ==typeof ( decimal)) result += (reader. Getdecimal (j). ToString () + ","); else result += ("null,"); } catch (EXCEPTION&NBSP;EX) { trace.writeline ("wrong filed "+j+" "+result"; conn. Close (); throw; } } trace.writeline (Result); }} while (reader. NextResult ());
Finally found the problem column!
In fact, a few points of oracledatareader knowledge.
Reader. Read () reader. IsDBNull (j) Reader. GetFieldType (j) Reader. NextResult ()
NextResult is the loop between multiple result sets. Because my procedure returns 20 cursor sets at a time.
You see, with OracleDataReader is so complicated, but I have found the problem column, from the library to modify the data into the accuracy within. You can do this:
OracleDataAdapter ODA = new OracleDataAdapter (cmd);
Oda. Fill (DS);
In two words, all the tables are dumped into the dataset at once. Don't be too cool, okay?
When Odp.net is used, the specified conversion is invalid