Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I'm working on simple code, the idea is to take a picture from an Access database.

I reused a code but having now this error:
ReadTimeout' threw an exception of type 'System.InvalidOperationException'.- when doing the
 Bitmap bmp = new Bitmap(ms,false);

Can anyone help me?
In the access database the type is OLE Object.

Thanks in advance

Just to be clear, the error is in Bitmap bmp = new Bitmap(ms,false);

What I have tried:

<pre>  try
            {
            cn.Open();
            cmd = new OleDbCommand("select * from [EQUIVALENCE TABLE]", cn);
            da = new OleDbDataAdapter(cmd);
            da.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    if (dr["Img"] != DBNull.Value)
                    {
                        img = ByteArrToImg((Byte[])dr["Img"]);                        
                        Bitmap bitmap = new Bitmap(img);                        
                        Graphics graphics = Graphics.FromImage(bitmap);                        
                        graphics.SmoothingMode = SmoothingMode.AntiAlias;
                        graphics.Flush();
                        bitmap.Save(path + "\\" + dr["file"].ToString() + ".jpg");
                        graphics.Dispose();
                        img.Dispose();
                        lblfile.Text = dr["file"].ToString();
                    }
                }
            }
            cn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                EventLog EL = new EventLog("ABS");
                EL.Source = "ABS";
                EL.WriteEntry(ex.ToString());
            }



Bitmap ByteArrToImg(byte[] b)
       {
           try
           {
               MemoryStream ms = new MemoryStream();
               ms.Position = 0;
               byte[] imgData = b;
               ms.Write(imgData, 0, Convert.ToInt32(imgData.Length));
               Bitmap bmp = new Bitmap(ms,false);
               ms.Dispose();
               return bmp;
           }
           catch(Exception er)
           {
               MessageBox.Show(er.Message);
               return null;
           }
       }
Posted
Updated 18-Mar-20 5:04am
v4
Comments
Richard MacCutchan 18-Mar-20 8:24am    
What actual data did you read from the data base? Chances are that it is not a bitmap.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900