index > .NET Framework Data Access and Storage > Help!!! Fail to update Oracle CLOB column on HP-UX

Help!!! Fail to update Oracle CLOB column on HP-UX

I tried to update one CLOB column in Oracle 9i, but the saved data in database is gibberish. It only happend when I use Transaction in .cs file. But if I remove the transaction related codes, it work.

Environment:
Client: Windows XP, Visual Studio 2005, System.Data.OracleClient 2.0
Server: HP-UX II for OS, Oracle 9i with American set as the Language and a character set of English US ASCII

Here are the code using transaction (not working version):

string selectSQL = "select configvalue from appconfig where configid = 1";
string newvalue = txtNewValue.Text.Trim(); // use "test value" at web form
lock (this)
{
DataTable dt = new DataTable();
OracleConnection conn = new OracleConnection(ConfigurationManager.ConnectionStrings["dbconn"].ConnectionString);
OracleCommand cmd = new OracleCommand(selectSQL, conn);
OracleDataAdapter da = new OracleDataAdapter(cmd);
OracleCommandBuilder ocb = new OracleCommandBuilder(da);
cmd.UpdatedRowSource = UpdateRowSource.None;
try
{
conn.Open();
da.Fill(dt);
if (dt != null && dt.Rows.Count > 0)
{
OracleTransaction trans = conn.BeginTransaction();
cmd.Transaction = trans;
try
{
dt.Rows[0][configfield] = newvalue;
da.Update(dt);
trans.Commit();
}
catch (Exception ee)
{
trans.Rollback();
}
finally
{
if (conn != null)
{
if (conn.State != ConnectionState.Closed)
conn.Close();
conn = null;
}
trans = null;
}
}
}
catch (Exception ex)
{}
finally
{
if (conn != null)
{
if (conn.State != ConnectionState.Closed)
conn.Close();
conn = null;
}
}
}

Anyone has any idea what's wrong with the code. It only happened with Transaction in .cs file. It's very weird.

Thanks.

AX

AXEFT

Hi AX,

I'm trying to reproduce this so I can investigate it, but I'm running into some problems. Can you provide the following information that might help me?

(1) SQL to create the table. Here is what I used:

create table appconfig (configid NUMBER CONSTRAINT configid_pk PRIMARY KEY, configvalue CLOB);

With the table like this, my OracleCommandBuilder fails to generate the UpdateCommand for the query you provided, because the query doesn't contain the primary key. Since your query only contains one column, and your problem description indicates it's a CLOB, I'm not sure how your OracleCommandBuilder is working, since you can't make the CLOB the primary key.

(2) How would you know if any errors are occurring? Your catch blocks don't output any information when errors occur. I would suggest adding some way to output the error message and call stack (e.g. ex.ToString()). I assume you stepped through this in a debugger, or somehow concluded no errors were occurring, but normally you wouldn't want to just eat the errors in this scenario.

(3) Are you sure the update is actually going through to the database? If so, how did you verify that? Is it because you have an initial value in the row, and it's actually changed after the code runs? Or have you run client or server-side tracing to verify what is being sent? System.Data.OracleClient is built on top of Oracle's OCI API, so you can use their OCI tracing to see what's happening at that level. For reference on how to do that, see: http://download-west.oracle.com/docs/cd/B19306_01/network.102/b14213/sqlnet.htm. That doc is for 10g, but at least the basic settings should work on 9i as well. For example, the following is what I use in my sqlnet.orato turn on OCI tracing:


trace_level_client=16
trace_file_client=client
trace_directory_client=c:\OraCliTraces
trace_unique_client=true

The folder you specify in c:\OraCliTraces can be anything you want, just make sure you create it before tracing. After you make these changes in sqlnet.ora, run your application. You should see the UPDATE statement being used in the trace.

Thanks,
Sarah




This posting is provided "AS IS" with no warranties, and confers no rights.
Sarah Parra - MSFT

Hello, Sarah,
Thanks for your help.

1. The configid is the primary key.

2. The value is saved to database, but the value is gibberish. No error occured. The app never go to catch block. I have the screen snapshot and I can send a copy to you.

3. Thanks for the trace info. I will do it later.

AX

AXEFT

If the configid is the primary key and you are using the SQL included in your code snippet, I still don't understand how your OracleCommandBuilder is able to generate the UPDATE statement.

Do you know what UPDATE statement is being used? You can get it using GetUpdateCommand on the CommandBuilder object. You can also get it out of the OCI trace, but GetUpdateCommand will show you what it looks like originally in .NET, as opposed to how it might look at the OCI level.

I'm not sure what you have a screen shot of, but you can e-mail it to me at the address in my forum profile, but REMOVE the "online" from the address. You can also send me your OCI trace if you capture one. I am not an expert reading those traces, but I can at least look for the significant operations relevant to this scenario.

Thanks,
Sarah




This posting is provided "AS IS" with no warranties, and confers no rights.
Sarah Parra - MSFT
reply 4

You can use google to search for other answers

 

More Articles

• help: I need to view all the tables in a SQL Server Dataset
• Interesting behavior causing: "There are no primary or candi...
• Seek suggestion on .NET support options
• Exception: DataTable internal index is corrupted: '5'. on ...
• jro.refreshcache on oledbconnection??? (provider=Jet)
• System.Transactions issue
• Add new Record in VB 2005
• Error when importing an Excel SS into a dataset
• System.Data.OleDb.DBBindings.Get_DBTIMESTAMP error on datefield
• SQLDataAdapter update to multiple tables through a single stored ...
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Best way to create multiline T-SQL in .N
• Tableadapter Update
• Personalization & Integrated Security
• Problem with SQL Server 2005 and IIS 6.0
• How to make NextGen based windows applic
• Crystal Report Linked to access database
• Microsoft Oracle .NET Data Provider Perf
• analysis services 2005 tutorial
• Internet Explorer VS Firefox
• detailview "Tipi di dati non corris
• transaction problem
• Parameters.Add - @MyParam doesn't get re
• Can not detach database right after back
• Global Caching
• Problem getting schema information: Allo

Hot Articles

• Error with Select statement with multilp
• Remoting large datasets and merging it a
• How to get a file stored in an Access da
• GetChanges - Update - Merge result in re
• How to retrive, view and manipulate tabl
• Connecting to SQL Database using Enterpr
• SqlDependency and which rows actually ch
• TransactionScope ignores timeout option
• Advice needed - persist data during a se
• DataFormatString for DateTime column
• Design Issue: Multiple definitions of db
• Concurrency Violation on 2 of 3 linked s
• Oracle Connectivity Problem
• System.NullReferenceException: Using Dat
• database connections string and getting

Recommend Articles

• Synchronize Replicated Access Database u
• Help with MS Access SQL Query
• System.Data.Design.TypedDataSetGenerator
• DESCRIBE STATEMENT
• VB.NET Front end for small amount of XML
• How to force a single line per data in a
• How to create a web services for retriev
• DataSet Vs DataReader????
• Read-only database problem after site in
• VB.Net How to make DataColumn of Image t
• Finding orphans among two datatables
• Determine Primary Keys using SqlConnecti
• Dataset to Xml file with sub nodes
• Internet Explorer VS Firefox
• Com Exception is unhandeled while execut