very strang problem

  • Thread starter Thread starter 2G
  • Start date Start date
2

2G

Hi,

I have one project containing all classes that access my db.
In another project I have some usercontrols that use these classes to access
the db and one of these usercontrols contains the following function:

private void cmdSImage_Click(object sender, System.EventArgs e)

{

OpenFileDialog ofd = new OpenFileDialog();

ofd.Title = "Select a image";

//ofd.Filter = "All files (*.*)|*.png;*.gif|PNG files (*.png)|*.png|GIF
files (*.gif)|*.gif" ;

if(ofd.ShowDialog()==DialogResult.OK)

{

// bimage = ofd.FileName.Substring(ofd.FileName.LastIndexOf("\\")+1);

//// FileStream fs = File.Open(ofd.FileName, FileMode.Open,
FileAccess.Read);

//// pctImage.Image = Image.FromStream(fs);

//// fs.Close();

}

ofd.Dispose();

}

Now here's the problem, from the moment I execute this by pressing on
cmdSImage and select a image and press ok , all my classes that access the
db fail on this.DBConn.Open(); where they open the dbconn and always get
following error :

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred
in system.data.dll



I just can't find what's wrong with it since this has nothing to do with my
dbconn and have also tried to completly rebuild the solution creating all
the project again and adding the existing classes but that also didn't help.

Anyone that may have a clue what's wrong ?



Thanks.
 
Hi 2G,

It may be related to this other odd problem I encountered when testing your code.
Setting the backgroundimage of the form with the image from the stream results in an OutOfMemoryException if you close the stream, but not if you use the image in a picturebox.

FileStream fs = new FileStream(ofd.FileName, FileMode.Open);
Image img = Image.FromStream(fs)
fs.Close();

this.pictureBox1.Image = img; // works fine

this.BackgroundImage = img; // causes OutOfMemoryException ???

Anyone know why?


Happy coding!
Morten Wennevik [C# MVP]
 
Hi, thanks for the reply,

I hadn't notice this problem, thanks for pointing it out but I do not think
it has to do with the problem I'm currently having since I don't even load
the image (code is in comments), I also removed the comments so i only had
Morten Wennevik said:
Hi 2G,

It may be related to this other odd problem I encountered when testing your code.
Setting the backgroundimage of the form with the image from the stream
results in an OutOfMemoryException if you close the stream, but not if you
use the image in a picturebox.
FileStream fs = new FileStream(ofd.FileName, FileMode.Open);
Image img = Image.FromStream(fs)
fs.Close();

this.pictureBox1.Image = img; // works fine

this.BackgroundImage = img; // causes OutOfMemoryException ???

Anyone know why?


Happy coding!
Morten Wennevik [C# MVP]
 
ctrl+enter :s

Hi, thanks for the reply,

I hadn't notice this problem, thanks for pointing it out but I do not think
it has to do with the problem I'm currently having since I don't even load
the image (code is in comments), I also removed the comments so i only had

private void GetImage(){

OpenFileDialog ofd = new OpenFileDialog();

if(ofd.ShowDialog()==DialogResult.OK)

{


}

ofd.Dispose();

}



but it had still the same effect when I select a file.
I'm thinking the OpenFileDialog overwrites some memoryaddress where my
dbconnection is located or something like this. Anyone else that may have
some comments on this?


Morten Wennevik said:
Hi 2G,

It may be related to this other odd problem I encountered when testing your code.
Setting the backgroundimage of the form with the image from the stream
results in an OutOfMemoryException if you close the stream, but not if you
use the image in a picturebox.
FileStream fs = new FileStream(ofd.FileName, FileMode.Open);
Image img = Image.FromStream(fs)
fs.Close();

this.pictureBox1.Image = img; // works fine

this.BackgroundImage = img; // causes OutOfMemoryException ???

Anyone know why?


Happy coding!
Morten Wennevik [C# MVP]
 
I am having this very same problem but in VB.net

Have you been able to get around this problem?
 
I was jusr wondering if you have sloved this problem

I am having this same issue but in VB.net
 
Back
Top