微软提供oracle的驱动默认是不支持TransactionScope,除非安装oracle相应的程序,但是odp.net即oracle提供驱动不存在此类问题,
namespace OracleTransactionScopeApp
{
using System;
using System.Data;
using Oracle.DataAccess.Client;
using System.Transactions;
using System.Data.Common;
class Program
{
static void Main(string[] args)
{
try
{
using (TransactionScope tran = new TransactionScope())
{
ExampleDao dao = new ExampleDao();
dao.Excute1();
dao.Excute2();
dao.Excute3();
tran.Complete();
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
Console.ReadLine();
}
}
public class ExampleDao
{
protected void Excute(Action<IDbCommand> action)
{
using (OracleConnection con = new OracleConnection("Password=\"password\";User ID=userid;Data Source=database;"))
{
using (OracleCommand com = con.CreateCommand())
{
try
{
con.Open();
action(com);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
finally
{
con.Close();
}
}
}
}
public void Excute1()
{
this.Excute(com =>
{
com.CommandText = "select sysdate from dual";
Console.WriteLine(com.ExecuteScalar());
Console.WriteLine(Transaction.Current.TransactionInformation.LocalIdentifier);
}
);
}
public void Excute2()
{
this.Excute(com =>
{
com.CommandText = "select sysdate from dual";
Console.WriteLine(com.ExecuteScalar());
Console.WriteLine(Transaction.Current.TransactionInformation.LocalIdentifier);
});
}
public void Excute3()
{
this.Excute(com =>
{
com.CommandText = "select sysdate from dual";
Console.WriteLine(com.ExecuteScalar());
Console.WriteLine(Transaction.Current.TransactionInformation.LocalIdentifier);
});
}
}
}
但是在使用的时候发现一个小问题,当数据库服务器是Oracle11时,客户端是Oracle10,而程序一直报用户名和密码错误,在查询相关资料后,发现oracle11的密码可能区分大小写的。解决方式,一个是设置数据库密码不区分大小写,第二个就是在密码上加上引号。
引用:
Thread: "ORA-1017: invalid username/password; logon denied"
分享到:
相关推荐
ODP.NET_Managed121020
Pro ODP.NET for Oracle Database 11g.pdf
使用ODP.net 操作oracle 数据库 使用ODP.NET访问oracle效率比data.OracleClient高
使用C#(Odp.Net)操作Oracle数据库:免安装Oracle客户端,利用即时客户端文件(11_2),与x64 Odp.Net,操作数据库。亲测可用。 x64的只能在64位系统上运行。而x86可以在32位和64位系统上运行。 x86下载路径:...
ADO.net ODP.net 实例,教程,源代码。PPT 实用性强 三层架构 为初学者量身定做
对于asp.net访问oracle数据库,微软已经再支持data.oraclecliet,意见使用odp.net来访问oracle了哦。比data.oraclecliet访问数据库效率更高的odp.net,使用微软的oraclehelper改写得到
ODP.NET—DLL 这是一个dll,直接引入即可。
不需要安装客户端就能访问oralce数据库的Oracle.ManagedDataAccess.dll
C#连接Oracle所需的ODP.NET,这里是从Oracle网站下载的, 现在在官网上下载的几乎都是12g版本了。
ODP.NET_Managed_ODAC122cR1ODP.NET_Managed_ODAC122cR1
net中使用ODP.net访问Oracle数据库(无客户端部署方法)
使用了,ODP.NET 方式链接数据库,只要把Oracle.ManagedDataAccess.dll引入取代以前的Oracle.DataAccess.dll即可。 这种方式也是oracle公司提供的,稳定性要比之前那种更好,而且也是免安装客户端的,目前还没测试...
官方ODP.NET开发文档(oracle 11g r2)
oracle ODP.NET 批量插入或更新
VS2010通过ODP.NET连接Oracol 11g所需DLL文件
ODP.NET_Managed_ODAC122cR1包含ODP。NET,仅托管驱动程序xcopy。安装说明包含在zip文件中。
被C#无客户端访问Oracle数据库的问题折磨了好久,终于整明白了。 需要的朋友可以下载自测。 资源提取自ODAC112040Xcopy_64bit 环境说明(开发环境系统要求是64位,其它的不限制可自测): 开发环境:win7 64位,VS...
微软企业库6版本,修改后支持odp.net,vs2015编译, 单独编译data项目,生成的两个动态库覆盖引用一下就可以了。
Oracle 10g 第 2 版 ODAC 和 Oracle Developer Tools for Visual Studio .NET 下载文件 ODTwithODAC1020221.exe 235 MB(247,296,458 字节) ODAC 安装说明 Oracle Developer Tools For Visual ...