使用Oracle Wallet。我已经验证了我可以通过SQL开发人员连接,并通过.NET PowerShell使用Oracle.ManagedDataTool.dll(核心和框架)编程连接。我正在尝试不安装Oracle客户端,只使用扩展连接字符串。
在PowerShell中使用:
Add-Type -Path "Oracle.ManagedDataAccess.dll"
$connectionString = "Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCPS)(HOST = XXXl )(PORT = 2484))(CONNECT_DATA = (SID = XXX)));User ID=XXX;Password=XXX!;Wallet_Location=c:\Users\XX\Documents\XX\wallet_v5;"
$con = New-Object Oracle.ManagedDataAccess.Client.OracleConnection($connection_string)
$con.Open()
我通过C#连接到钱包的同一数据库时遇到问题:这是一个简单的控制台应用程序。
using Oracle.ManagedDataAccess.Client;
//OracleConfiguration.TnsAdmin = @"c:\Users\XXX\Documents\XXX\wallet_v5";
OracleConfiguration.WalletLocation = @"(SOURCE = (METHOD = file)(METHOD_DATA = (DIRECTORY=c:\Users\XX\wallet_v5)))";
OracleConfiguration.SqlNetWalletOverride = false;
OracleConfiguration.SqlNetAuthenticationServices = "(tcps)";
OracleConfiguration.OracleDataSources.Add("V2SLCPRD", "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCPS)(HOST=XXX)(PORT=2484))(CONNECT_DATA=(SID=V2SLCPRD)))");
OracleConfiguration.StatementCacheSize = 25;
OracleConfiguration.SelfTuning = false;
OracleConfiguration.BindByName = true;
OracleConfiguration.CommandTimeout = 60;
OracleConfiguration.FetchSize = 1024 * 1024;
OracleConfiguration.SendBufferSize = 8192;
OracleConfiguration.DisableOOB = true;
OracleConfiguration.TraceOption = 1;
OracleConfiguration.TraceFileLocation = @"C:\RBI";
OracleConfiguration.TraceLevel = 7;
OracleConnection orclCon = null;
try
{
orclCon = new OracleConnection("User ID=XXX;Password=XXX;data source=V2SLCPRD");
orclCon.Open();
OracleCommand orclCmd = orclCon.CreateCommand();
orclCmd.CommandText = "select * from wf_employees where rownum <= 10 ";
OracleDataReader rdr = orclCmd.ExecuteReader();
while (rdr.Read())
Console.WriteLine("Employee Name: " + rdr.GetString(0));
Console.ReadLine();
rdr.Dispose();
orclCmd.Dispose();
}
finally
{
if (null != orclCon)
orclCon.Close();
}
下面是调用堆栈:
Oracle.ManagedDataAccess.Client.OracleException
HResult=0x80004005
Message=Oracle Communication: Failed to connect to server or failed to parse connect string
Source=Oracle Data Provider for .NET, Managed Driver
StackTrace:
at OracleInternal.ConnectionPool.PoolManager`3.Get(ConnectionString csWithDiffOrNewPwd, Boolean bGetForApp, OracleConnection connRefForCriteria, String affinityInstanceName, Boolean bForceMatch)
at OracleInternal.ConnectionPool.OraclePoolManager.Get(ConnectionString csWithNewPassword, Boolean bGetForApp, OracleConnection connRefForCriteria, String affinityInstanceName, Boolean bForceMatch)
at OracleInternal.ConnectionPool.OracleConnectionDispenser`3.Get(ConnectionString cs, PM conPM, ConnectionString pmCS, SecureString securedPassword, SecureString securedProxyPassword, OracleConnection connRefForCriteria)
at Oracle.ManagedDataAccess.Client.OracleConnection.Open()
at Program.<Main>$(String[] args) in XXX:line 21
This exception was originally thrown at this call stack:
System.Collections.CollectionBase.System.Collections.IList.get_Item(int)
System.Security.Cryptography.X509Certificates.X509CertificateCollection.this[int].get(int)
OracleInternal.Network.TcpsTransportAdapter.Negotiate(OracleInternal.Network.ConnectionOption)
OracleInternal.Network.TcpsTransportAdapter.ConnectIterate()
OracleInternal.Network.OracleCommunication.ConnectViaCO(OracleInternal.Network.ConnectionOption, OracleInternal.Network.AddressResolution)
Inner Exception 1:
NetworkException: Oracle Communication: Failed to connect to server or failed to parse connect string
Inner Exception 2:
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
1条答案
按热度按时间c6ubokkw1#
我让我的C#.net核心控制台应用程序使用旧的NuGet包2.18.180与Oracle钱包工作/连接。我不知道为什么旧版本的作品与最新版本还没有。