我需要从数据库中检索图像并将其保存到磁盘。在数据库中,图像以二进制格式存储,但列的数据类型为varchar(5000)
.
这是我用于检索图像并将其保存到磁盘的代码
public void CreateImageDataUsingDataReader_ForNetezzaDB()
{
string strDbConn = string.Empty;
string strImageFileName = string.Empty;
string strImageData = string.Empty;
string strImgSavePath = string.Empty;
string strQuery = string.Empty;
Byte[] byteImageData;
MemoryStream stmImageData = new MemoryStream();
Image saveImage;
try
{
//---open the database connection
strDbConn = ConfigurationSettings.AppSettings["NetezzaDBConnection"].ToString().Trim();
OleDbConnection dbcon = new OleDbConnection(strDbConn);
dbcon.Open();
strQuery = "select name,signature_vod__c from sfb_call2_vod where signature_vod__c is not null limit 10";
OleDbCommand cmdSelect = new OleDbCommand(strQuery, dbcon);
OleDbDataReader imageReader = cmdSelect.ExecuteReader();
if (imageReader.HasRows)
{
while (imageReader.Read())
{
strImageFileName = imageReader["name"].ToString().Trim();
strImageData = imageReader["signature_vod__c"].ToString().Trim();
stmImageData.Seek(0, SeekOrigin.Begin);
//converting string to byte array
byteImageData = Convert.FromBase64String(strImageData);
//---create Memory stremm from the Image Byte data
stmImageData.Write(byteImageData, 0, byteImageData.Length);
//--saving the image
//saveImage = Image.FromStream(stmImageData);
using (saveImage = Image.FromStream(stmImageData))
{
strImgSavePath = ConfigurationSettings.AppSettings["ImageSavePath"].ToString().Trim();
saveImage.Save(strImgSavePath + strImageFileName + ".png", System.Drawing.Imaging.ImageFormat.Png); ///---error comes in this line
}
}
}
imageReader.Close();
dbcon.Close();
stmImageData.Close();
stmImageData = null;
}
catch (Exception ex)
{
throw new Exception("Error Occured in method CreateImageDataUsingDataReader " + ex.Message);
}
}
但我不断收到错误消息:
GDI+ 中出现一般错误。
如果我为 SQL Server 数据库执行相同的代码,它可以正常工作,但问题只出现在 Netezza 数据库中
请帮我解决这个问题