下面的代码在连接到SQL Server时工作正常,但是当我尝试将其指向Oracle数据库时会引发异常。该异常返回一个空的错误消息,所以我不太确定接下来要看什么。任何帮助将不胜感激。我在发布本文之前进行了搜索,并且所有与oracle有关的问题似乎都使用Oracle ADO方法而不是ODBC。
以下是read_blob_file函数的变量设置:
string dbname = "oracle_odbc_database";
string uid = "username";
string pwd = "password";
string sql = "INSERT INTO CD_ATTACHMENT (\"ATTACHMENT_ID\",\"DESCRIPTION\",\"ATTACHMENT\",\"CREATE_DATE\",\"MIME_TYPE\",\"CREATE_USER_ID\",\"CREATE_APP_ID\",\"UPDATE_DATE\",\"UPDATE_USER_ID\",\"UPDATE_APP_ID\") VALUES (''YPoem'','NULL',?,'to_date('10/8/2013 6:30:41 AM','MM/DD/YYYY HH:MI:SS AM')','NULL',''EFPUFC1B(AMERICAS\\EFPUFC1B)'',''OpenWells'','NULL','NULL','NULL');";
string blob_value = "'c:\\ATTACHMENT\\00AfKOHF-ATTACHMENT.blob'";
string blob_column = "ATTACHMENT";
private int read_blob_file(string dbname, string uid, string pwd, string sql)
{
int rtncmd = -99;
try
{
using (var conn = new OdbcConnection("DSN=" + dbname + ";UID=" + uid + ";pwd=" + pwd))
{
conn.ConnectionTimeout = 1500;
conn.Open();
using (var cmd = conn.CreateCommand())
{
if (blob_value != "")
{
blob_value = blob_value.Replace("'","");
using (var inputStream = File.OpenRead(blob_value))
{
cmd.Parameters.AddWithValue(blob_column, File.ReadAllBytes(blob_value));
}
}
cmd.CommandText = sql;
rtncmd = cmd.ExecuteNonQuery();
}
conn.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return rtncmd;
}