当我用VB.NET ,or C#,or ASP.NET 编程时,我会update a table on a remote oracle database, 下列问题总是发生;
ORA-02041 client database did not begin a transaction
我试过很多方法都没解决掉;终于我在帖子上找到解决的办法;有点象大海捞针:
我提供如下解决方法 :
Try this. It works for Oracle 8.1.7.0.0 and version 1.1 of .Net Framework. VS 2003
Dim sConnection As String
Dim sType As String
Dim oDS As New DataSet
GetDataSet = True
sConnection = "Provider=OraOLEDB.Oracle;Password=" & sDatabasePwd & ";User ID=" & sDatabaseSchema & ";Data Source=" & sDatabaseInstance & ";[B]DistribTX=0;[/B]"
Dim oConn As New OleDbConnection(sConnection)
Dim oDA As New OleDbDataAdapter(sSql, oConn)
Try
'oDA.MissingSchemaAction = MissingSchemaAction.AddWithKey
oDA.Fill(oDS, TableName)
Catch oException As Exception
sError = oException.Message
GetDataSet = False
Finally
oDA.Dispose()
oDA = Nothing
End Try
请你特别注意这条语句,特别重要呀...
[B]DistribTX=0;[/B]
这就是解决问题的关键点..
相关的技术文挡请参考下面的内容:
OraOLEDB offers provider-specific Connection String attributes, which are set in the same way as the Provider and User ID are set. The provider-specific connection string attributes are:
CacheType - specifies the type of cache used to store the rowset data on the client. See "OraOLEDB-specific Connection String Attributes for Rowsets".
ChunkSize - specifies the size of LONG or LONG RAW column data stored in the provider's cache. See "OraOLEDB-specific Connection String Attributes for Rowsets".
DistribTX - enables or disables distributed transaction enlistment capability. See "Distributed Transactions".
FetchSize - specifies the size of the fetch array in rows. See "OraOLEDB-specific Connection String Attributes for Rowsets".
OLEDB.NET - enables or disables compatibility with OLE DB .NET Data Provider. See "OLE DB .NET Data Provider Compatibility".
OSAuthent - specifies whether operating system authentication will be used when connecting to an Oracle database. See "Operating System Authentication".
PLSQLRSet - enables or disables the return of a rowset from PL/SQL stored procedures. See "OraOLEDB Custom Properties for Commands".
PwdChgDlg - enables or disables displaying the password change dialog box when the password expires. See "Password Expiration".
UseSessionFormat - specifies whether to use the default NLS session formats or let OraOLEDB override some of these formats for the duration of the session. Valid values are 0 (FALSE) and 1 (TRUE). The default is FALSE which lets OraOLEDB override some of the default NLS session formats. If the value is TRUE, OraOLEDB uses the default NLS session formats.
Note that this connection attribute does not appear under the HKEY_LOCAL_ MACHINESOFTWAREORACLEHOMEIDOLEDB registry key.
The DistribTX attribute specifies whether sessions are enabled to enlist in distributed transactions. Valid values are 0 (disabled) and 1 (enabled). The default is 1 which indicates that sessions are enabled for distributed transaction enlistments.
Applications using Microsoft Transaction Server must have DistribTX set to 1, the default.
More detail , pls, refe this Web
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30193/viewspace-90012/,如需转载,请注明出处,否则将追究法律责任。