Jump to content
Xtreme .Net Talk

PlausiblyDamp

Administrators
  • Posts

    7016
  • Joined

  • Last visited

Everything posted by PlausiblyDamp

  1. You can only have one active DataReader on a connection at any given time, however there is nothing preventing you using more than one DataReader as long as you close each one before using the next. I would generally keep the connection open till the last Reader in the routine has finished and then close it, I would close each Reader as soon as I have finished using it - just to prevent having multiple active ones by accident.
  2. Dim s As String = Convert.ToChar(34) & "c:\program files" & Convert.ToChar(34) would work, although this does rely on you guessing the correct location for the program files folder... A better soulution would be to use Dim s As String = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)
  3. If you are doing this from ASP.Net your objects are going to be created / destroyed every page refresh anyway (unless you are storing them in a session or similar); keeping a connection open for the duration may be counter productive.
  4. If you really, really must force a garbage collection then avoid GC.Collect() and try using GC.Collect(0). If you do not specify a parameter then it will do a full memory collection (generation 2), any objects that are not eligible will be promoted a generation and will potentially stay in memory longer. Generally it is best to leave the memory management to the garbage collector unless you can prove that is the problem. Often just remebering to close / dispose of resources will prevent excesive memory consumption.
  5. You may find some of the things mentioned in this thread useful. Do be aware that unless you really have a requirement for managing your memory it is probably not worth the effort. Rarely is manually calling the GC beneficial, and even when it is you may find that just closing / disposing of objects in a timely fashion is a better choice. MS has invested a lot of time and effort in the GC and forcing it to collect will often upset it - the GC will self tune over the duration of your app's execution and calling Collect can cause objects to stay in memory longer than if you left it to do it's work.
  6. In that case tough. If a programmer cannot remember to close a resource after he has used it then he can expect problems; giving a Dispose / Close method provides the developer with a means to manage the resources if the desire to do so, but they can still rely on automatic clean-up some time in the future - their choice. Out of interest are you coding in VB or C#? If C# then it even has a keyword (using) to simplify using a Dispose methods. Just out of completeness - the reason you cannot close a connection in a finalizer is because there is no guarenteed order in which finalizers will be executed. If your class is being finalized then the runtime may have already closed and finalized the connection anyway. As a developer you really should provide a manual way to close expensive resources (DB connections, file handles etc.)
  7. You may get better mileage out of disposing the Bitmap / Graphics objects when finished with them rather than relying on the GC being invoked manually to clean up the resources.
  8. If you must keep the connection open (although as michael_hk pointed out connection pooling may alleviate the performance issues) then relying on a finalizer is a Bad Thing™. By design the time till a finalizer being called is non-deterministic, about the only thing you can say for sure is that it will get called sometime between your application freeing up the reference to the variable and the application shutting down... You are probably better of giving your class a close method (or similar) and requiring users of your class to call the methods when they have finished with the object. Even better I would suggest you look at implementing the IDisposable interface in your class and do your clean up there.
  9. Why did the computer programmer die in the shower? The directions said: Shampoo, rinse, repeat.
  10. Could you not use the .GetThumbnailImage method to do this? Should do what you require - not sure how good the resultant image quality is though.
  11. If a variable is only needed within a single function, declare it within that function; this helps reduce the chance of either cluttering up the namespace with lots of similar variable names, or accidentaly changing the value of a variable when calling another method. If the variable needs to be used in more than one function then either consider passing it as a parameter or declaring it at the class level (outside of a function). The use of default above just means whatever processing should be done if neither of the if statement conditions are met.
  12. Just noticed you are using d:Image rather than d:\Image in your sample above - is that a type here or in your real code? If that doesn't fix the problem could you post the exact exception type / message that is being thrown along with the full path that it is attempting to read from.
  13. At the top of the code module add Imports System.Net nd things should be good
  14. I think you just use a ? no name etc sSQL = "UPDATE [sales] SET [Client]=?, [sDate]=?, [Gross]=?," & _ " [Net]=?, [Product]=?, [Developer]=?, [Hours]=?, [Paid]=?"
  15. to run a .Net exe the target system must have the framework installed. If the target PC does meet this requirement then deployment is a simple case of building the exe and copying it and any dependant Dlls (should be in the bin folder along with the exe) to the target PC (or floppy).
  16. Wizard (may I call you that?) - does it give any further information as to which line / parameter is generating the error? From a quick glance it looks fine. Edit: something just came to mind: IIRC OleDb doesn't support named parameters - i think you need to just use a ? character in place of the parameter and make sure you add them in in the correct order; which could explain the mismatch as you are adding them in a different order to the sSQL string. stustarz - the problem with that approach is that it can lead to problems with strings needing to be converted by the DB (dates are a prime example where this can be fun), opens your system to potential security exploits (search for SQL Injection) and can make the code more difficult to maintain as the size of the SQL string increases / number of parameters increase as well as the joy of handling textboxes that contain double or single quotes or both types of quotes (work on a BOM system where measurements are given as 10' 6" and see what happens)...
  17. Not to state the obvious but this is a .Net forum ;) and unless you need to use C++, VB and C# are a hell of a lot easier to use and overall a more productive environment IMNSHO. Don't take that as C++ isn't wanted here - just that it's not the primary language for most folk here as far as I am aware. (perhaps more questions and postings from those who do use it may draw in a larger audience and prove me wrong - so please don't stop)
  18. In C# all conversions / casts are strict - there is no way to turn it on or off.
  19. At the end of the day MSDN is just one of the options provided by Microsoft as a source of help, ultimately your mileage will vary depending on how you approach it as a source of documentation and how you phrase your search criteria. Personally I tend to find it useful when needing to lookup method syntax, information regarding exceptions that may be thrown, acceptable ranges for parameters etc. Pretty much the stuff I would expect from library documentation. Yes the sample code included can be of variable quality - however other resources such as the 101 samples, http://www.gotdotnet.com, channel9 etc also provide another source of information and examples. If you have an issue with MSDN etc. why not take it up with Microsoft and let them know your issues? As to why this forum exists - people will need help regardless of the language being used and a forum can be more than a simple source of code samples. If VB6 was so simple what was the need for the plethora of VB6 related forums? They are (or were depending on your current language choice) a valuable resource - just the same as this forum (hopefully) and others are a valuable resource to .Net programmers. A programming language, just like a spoken language, can be simple and elegant - this does not preclude it from being able to express complex concepts; concepts which people may need external input to be able to express correctly or with maximum effect. This isn't always the fault of the underlying language or the person using it, but surely seeking help in a constructive way and then learning from this is how we progress in life.
  20. Are you doing this from an ASP.Net application? If so then you need to make sure your web application has access rather than your login account. Search these forums for several possible solutions.
  21. The requirement to support multiple clients concurrently is a much more convincing argument for considering threading as a solution. However taking single threaded code and making it execute on multiple threads isn't always a simple experience, often the complexities of syncronisation and the pain of debugging can be a major obstacle to overcome.
  22. If the memory is not being freed up when the process completes there is no guarentee that moving it to a seperate thread will change things. Is this causing problems due to the memory utilisation or is there still ample memory free after the process completes? If the later then it is probably just the GC being its lazy (by design) self. If the former then it may be more to do with how you are allocating memory within the aRequest.DoSomething(aRequest) call.
  23. Dim i As Integer i = datetime.DaysInMonth(, )
  24. The MS certifications are given out based on the qualifications you have, not what you want (if that makes sense). i.e. If you have the requisit exams for the MCAD you get the MCAD, if you then do a few more and qualify for MCSD you are both an MCSD and an MCAD. If you did a couple extra that could get you your MCDBA and now you would have all three qualifications to your name. Also your transcript on the MS web site tracks them all and when they where achieved - if you upgrade to the 2005 versions (whatever they will be called) you would have both the existing and the new to your credit.
  25. Page.Response.Charset = "utf-8"
×
×
  • Create New...