|
So if I have a class for DataAccess and I call it just to make the connection and return a dataset, should I also have a .Dispose in that class that disposes of the Connection Object everytime and any data adapters etc...?
Cleako
|
|
|
|
|
You should be closing your database connection when you're done with the SQL query. NEVER hold open an SQL connection longer than is absolutely necessary. SQL server licenses are expensive. Holding a connection open for the life of your application hogs that license so no other application can use it when you're not using it. Remember, Windows and Servers are SHARED resources, so you have to write your code to work and play nice with others.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Oh no, dont mark me as a bad coder! I wont be able to answer questions in good conscience again! I always close the connection in the Finally block after I use it. What I was asking as an example are what objects in that class are "Disposable"? Would I not only call a CN.Close but also a CN.Dispose? I think you can call a StreamReader.Close/Flush/Dispose.
So the path that got me to where I am right now is I havent used Implements IDisposable before. I also lost touch with my .Dispose self somewhere along the line and I guess I need to get back in touch with it.
The code I have "inherited" implements the IDisposable in a data access class. I dont know why but it does. The information I have read about Implements IDisposable makes it sound as if you only call that with COM objects, COM wrappers, unmanaged code calls, etc... Im trying to figure out the boundary of crazy "Disposing" and necessary "Disposing"
Thanks!!
Cleako
|
|
|
|
|
cleako wrote: Im trying to figure out the boundary of crazy "Disposing" and necessary "Disposing"
Add to your list that you should implement and call dispose on any class that holds on to an object that implements IDisposable as well. For example:
Class A implements IDisposable.
Class B holds a reference to an instance of class A as a field (member variable)
Class B needs to implement IDisposable because it holds an object of class A.
The Dispose method on class B calls the Dispose method on class A.
Also remember to implement a Finalizer method that calls Dispose on any class that implements it. This is to ensure that any object that is being garbage collected by the system and implements Dispose actually gets disposed. It is a final safe guard against accidentally holding on to things that should have been released. Once the object is garbage collected nothing can release the resource. This causes your application to leak memory, use up resources and eventually implode under its own weight.
|
|
|
|
|
When I minimize a child form in VB.Net it always goes to the bottom left corner. when I try to reference it from the parent and move it to the right some it just sits there, it seems like there is a property holding it. When minimized I can take my mouse and move the minimized form and it will then open and minimized to that location. Any help will be appriciated.
|
|
|
|
|
try ChildForm.SetBounds(300, 300, 0, 0)
|
|
|
|
|
that is only changing the form when it is restored, not the minimized title bar part.
|
|
|
|
|
i couldn't find a way to do what you asked about so by using this technique you can "simulate a minimize" by setting the size to 0,0 which will allow you to control the location.
in the form's resize event check if the windowstate = minimize and if it is, set the window state to normal then use the setbound to shrink it and to place it where you want. (just an idea)
|
|
|
|
|
Can anyone tell me how to use a command button to change the font of the writing on a form and another button to change the colour of the font on the form?
Using: Visual Basic.net 2002
Thank you!
-- modified at 12:48 Monday 8th January, 2007
|
|
|
|
|
1) your obviously are going to be dealing with the click events of both buttons
2) are you hard coding the font or do you want the "wizards" to pop-up and let them choose?
|
|
|
|
|
I would like the wizards to pop up and to let them choose as long i can change both font and colour
|
|
|
|
|
Ex:
'font
Me.Font = New System.Drawing.Font("GeoSlab703 Lt BT", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
'color
Me.ForeColor = System.Drawing.Color.Red
use the 'font dialog' control and 'color dialog' control from the toolbox to allow the user to choose...
|
|
|
|
|
|
help..plz help me how to read/eject USB flash drive serial number..plzz
tenkz a lot..its a big help..
gladz
|
|
|
|
|
you could try WMI to get the serial, i don't know how to eject it though...
|
|
|
|
|
Hi all,
I'm trying to write shoot date on the images from exif datas. I'm using Graphic.DrawString but it's not working. Weird thing is, when debugging it writes but when running not! My code is very simple;
Dim f As New Font(FontFamily.GenericSerif, 8.5F, FontStyle.Regular, GraphicsUnit.Point)
Dim graph As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(_img)
graph.DrawString(exifListBox.SelectedItem.ToString(), f, Brushes.Black, CSng(_img.Width) - 100.0F, CSng(_img.Height) - 30.0F)
Why it is not working when running?? Anybody has an idea?? Thanks...
Savas Cilve
|
|
|
|
|
Did you call Dispose() on the Graphics object (graph in your code) when you were done drawing with it?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Yeah I did it after your response but nothing changed
|
|
|
|
|
You might want to include the code around this code. There's something else wrong we can't see because there's not enough code to show us what else is going on.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
There is nothing around this code. But I solved this issue with adding
pictureBox.Image = _img
just after the graph.DrawString(...)
I guess my description of the issue let people think wrong
Thanks so much for your interest..
Savas Cilve
|
|
|
|
|
Yeah, if you show the picture or put it in a PictureBox, THEN make changes to the image, the changes won't be seen until you assign the picture to the PB again or redraw the screen image of the bitmap.
Changes to the bitmap image are NOT automatically updated in the controls that are showing them.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
|
|
BinaryFormatter.Serialize works well but BinaryFormatter.Deserialize throws an Exception
"The Assembly ProjectManagement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null can not be found."
The Assambly lays in the same Directory like the DLL that is Serializing.
What can I do?
mfg
|
|
|
|
|
The listbox has a member "indexfrompoint" that returns the index of the item at specific coordinates. Is there a reverse function that gives the coordinates of an item with a given index?
|
|
|
|