我的Oracle连接失败。我明白了:
SqlCommand失败,原因是:类型初始值设定项 ' Oracle.DataAccess.Client.OracleConnection'抛出异常。
内部例外是:
字典中没有给定的密钥。
有什么想法吗?
代码:
try
{
var connectionString = OracleSqlUtils.CreateConnectionString(credential.Value, ssisPackage: false);
using (var sqlConnection = new OracleConnection(connectionString))
{
if (sqlConnection.State != ConnectionState.Open)
{
sqlConnection.Open();
}
using (var sqlCommand = new OracleCommand(context.ReplacementPlaceholders(this.Command), sqlConnection))
{
object sqlResult;
// Set command Timeout
sqlCommand.CommandTimeout = timeout;
// Adds all the parameter
foreach (var parameter in parameters)
{
if (parameter.ParameterName == "@JobID")
{
var a = new System.Data.SqlClient.SqlParameter("@JobID", SqlDbType.VarChar);
a.SqlValue = parameter.Value.ToString();
sqlCommand.Parameters.Add(a);
}
else
{
sqlCommand.Parameters.Add(parameter);
}
}
this.LocalLogger(TraceLevel.Verbose, "Start SqlCommand: {0}", sqlCommand.CommandText);
switch (this.CommandType)
{
case "XmlReader":
sqlResult = sqlCommand.ExecuteXmlReader();
break;
case "NonQuery":
sqlResult = sqlCommand.ExecuteNonQuery();
break;
case "Reader":
sqlResult = sqlCommand.ExecuteReader();
break;
//case "Scalar":
default:
sqlResult = sqlCommand.ExecuteScalar();
break;
}
result = SqlCommandValidation(context, sqlResult);
}
}
}
catch (Exception ex)
{
this.LocalTracker(ExecutionMessageType.Error, "SqlCommand Failed due to: {0}", ex.Message);
this.LocalLogger(TraceLevel.Error, "stackTrace: {0}", ex.StackTrace);
context.JobResultStatus = JobResultStatus.Fail;
}
使用的Oracle连接字符串:
数据源= XXXXPRD;用户ID = XXXXX;密码= XXXXXX;