.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Disposing things

Posted By:      Posted Date: October 18, 2010    Points: 0   Category :ASP.Net

Hi Everybody,

I have noobishly written an ASP.Net without any Dispose methods for unmanged objects. The object I am using are Sqlconnection, Sqlcommand and SqlDataReader. My application on my shared host shows very high resource usage, and I'm the only one using it. Which seems to me like a badly designed app. Because it's done in C# ASP.Net 3.5 the garbage collection should handle managed objects without my intervention correct? But it doesn't handle unmanaged objects I think.

So I had a look at FxCop and ran it on my app. But it is coming up with no error for "Implements IDisposable correctly" in my whole app. This seems odd since I have not used the Dispose method once. So here is a section of my code for example. Is this code leaking memory? most of my code is the same with different params tables etc.

public List<Classy> Get_Classy(int classyId)
        List<Classy> classyList = new List<Classy>();
        using (SqlConnection connection = new SqlConnection(connStr))
            SqlCommand command = new SqlCommand();
            command.CommandText = "SELECT * FROM ClassyStore WHERE classyId = @classyId";
            command.CommandType = CommandType.Text;
            command.Connection = connection;

View Complete Post

More Related Resource Links

SharePoint 2007 Workflows - Things to Consider Before You Start

SharePoint 2007 (MOSS) utilizes the Workflow Foundation (WF) to enable workflows on lists and content types. But before you start doing cartwheels there are few things you should know before you get started. The experiences I'll be discussing are not from book smarts but from building real MOSS solutions that are in production today.

Usability in Practice: When Things Go Wrong


This month our usability experts explain what it takes to create informative, useful error messages.

Dr. Charles Kreitzberg and Ambrose Little

MSDN Magazine January 2009

Editor's Note: Some Things Are Easier Said Than Done


Executive Editor Josh Trupin gets himself in trouble with live electrical current and a penchant for twiddling.

Joshua Trupin

MSDN Magazine October 2006

What is the best way to add an extra row to the bottom of a listivew for such things as totals, etc.

 I can add a row to the bottom of a listivew by inserting a table after the layouttemplate in a listview.  It works fine for me to call the added controls from code-behind and chane the control values. Since my listview changes width dynamically depending on the contents of the data, my added table columns don't match up.  I have tried to access the width property of the table and then match the new ones with codebhind, but it doesn't seem to work. I am simply trying to add a row to the bottom of the listview to provide for totals of the columnts.  What is the best way to to that?   Thanks

Problems with Farm Account magically losing permissions to certain things

I don't know what's going on, but this has now happened two times in a row during my rebuild from TP to Beta (completely new build from the OS up).  I'm using the same service account (domain account) as my setup and farm account.  While logged in with my farm account, I install the SP2010 pre-reqs, then the bits, then give it dbcreator and securityadmin roles in SQL, then run the SPT wizard.  Within the wizard, I specify the same account as my farm account, and all works fine and dandy.  After it's done, I'm able to get into Central Admin with this same account and see/do everything.After working with things a while and following the MS instructions for getting the User Profile SA working, if I reboot or logout/login, then I suddenly don't have access to some very important things, such as:- System Settings > Manage Services on Server.  It just disappears completely- Security > Configure Service Accounts.  This does not disappear, but clicking on it causes a prompt saying "Error:Access Denied."  Previously, I was able to go in here and set my service accounts for things like search, user code service, etc (I set them to the proper service accounts)- Configuration Wizards > Launch Configuration Wizard.  I used this multiple times when getting my farm setup, but now it's gone.I've gone so far as to make my farm account all of these things:- Member of B

disposing SPSite and SPWeb objects?

hi          can i code using(SPSite oSite=SPContext.Current.Site) {    using(SPWeb oWeb=oSite.OpenWeb()) {} } or should i code like this SPSite oSite=SPContext.Current.Site; using(SPWeb oWeb=oSite.Openweb()){} which is better? i am trying to code this inside ItemAdding Event handler. please suggest

What all things one need to keep in mind while converting Asp.net 3.5 project tot Asp.net 4.0 ?

Hi,What all things one need to keep in mind while converting Asp.net 3.5 project tot Asp.net 4.0 ?Are there any issues regarding use of third party controls like Telerik ?Kindly guide... Thanks in advance.

Things I like about Scala

I'm excited about Scala (see Scaling the Cliffs to Scala ), one of the new Object-Fuctional languages that have emerged recently.  So, what excites me?  Let's list a few cool features. Everything is an object. Scala functions are really and truly first-class objects. Let's not forget that Scala gives us Closures! Mixins really rock!  They bridge the gap between multiply inheriting from interfaces and multiply inheriting from classes. Traits are like Java interfaces, but with implementations (behavior).  They provide a mixin composition mechanism I haven't had in other languages. Scala pays lots of attention to properly using mutability and immutability.  From having declarations of val vs. var to Value Objects and "side-effect free" functions, Scala provides the underlying support necessary to help us with multi-threading, multicore processing, and multi-processing.  Scala's implementation of concurrency and its Actor Framework make it one of the most interesting new languages around. I would recommend a study of Scala just for these benefits alone.  They're largely why I decided to use Scala for development of Chronoscope, the product on which I'm working at the moment.  

How do you write a program that can search for things on Google?

I just finished a web scraper so I am not brand new to this but I don't know whow to have my program fill in the fields for a web form. Basically, there is a web application we use at work which I want to integrate with. The first thing you have to do is tell the web app that you are searching by city (via drop down list). The page refreshes. Then you type the name of the city into a text box and hit submit to get your results. I think it might be done in ASP.NET I can't rememebr off the top of my head.   But just for a Hello World kind of app can someone tell me how to write a program that can do a search on Google? Like what does the request look like?

SEHException in Finalyzer while disposing SoftHandles



Hi All,

     I am hitting with SEHException while disposing Softhandles which are internal to .NET Framework. Can you please suggest me a way to how to solve this issue ? When i check the stack, almost all the softhandles are pointing to the same object, that surprises me more. Please do check the Windbg output :


!threads output


  0    1 2fd4 0015b790      a020 Enabled  00000000:00000000 00163f78     0 MTA
   2    2 3174 0016e5f0      b220 Enabled  00000000:00000000 00163f78     0 MTA (Finalizer) System.Runtime.InteropServices.SEHException (0c3e9468)
   3    5 4be8 00195d30      b220 Enabled  00000000:00000000 00163f78     0 MTA
   4    7 40ac 001b8798      b220 Enabled  00000000:00000000 00163f78     0 MTA
   6    9 4b50 001c6d08   200b220 Enabled  0000

things to consider when loading a lot of data to a big table


What are the considerations when loading a large amount of data to a large table?

One thing to consider are the indexes because they need to get rebuilt. One advice I had from someone is to drop the index, load the data, and finally re-create the index. Is this faster than loading without dropping the index?

What other considerations or concerns are there? What about data isolation? If it take a while to load the data, are the users locked out from selecting from the table? I would try to test this, but not sure how I can come up with large enough data set to play with.

New to SSIS and kind of banging my head a little as to if I'm doing things right



I am trying to understand using SSIS how I can merge a 'sales order header' table and 'sales order transaction' into a 3rd database table. 

I need to create a 3rd table with the 'order number', 'invoice date' and 'customer' fields then on the same row have the transaction entrys.

The reason I need to do this is I then also need to run the new table against the customer table to find what currency they are using and read the conversion rate from a currency table based on the currency and year then write the currency code into the 3rd table that was created and run a calculation on the values in the row to match that currency rate to ensure each transaction of each order for each customer is calculated from the correct currency back into a single currency for all records.

My theory was to read the header table and establish how many records were in there then do the same for the transaction table. Then build a nested loop on the two values to ensure that as i read a header record it scans the transaction table for all transactions for that order number and write the data to a new table then moves on to the next order header and repeats the process until all header records are read. This is the part I am stuck on building this correctly in SSIS. I have looked for some examples or pointers

New ways of doing old things in MVC


This is my first forray into ASP.NET MVC, having been doing WebForms for nearly 6 years now. I've read through various tutorials and guides on getting started with MVC, but I've a few questions about how you're meant to do things:

UserControls for entities

In an application I wrote a few years ago (using WebForms) there were many entities that had an associated postal address (which existed as an instance of an Address class), so I created a UserControl that contained fields for working with addresses. During the page lifecycle I would pass the business object's .Address property to the UserControl for display and for population upon a successful and valid postback.

How would I do something like this in MVC? My current project has a similar situation where common sets of fields are repeated throughout the application and all 'map' to the same class.

Modifying the page/view on 'postback'

Say I'm working on a data-entry form for an online B2B ordering system, where the user manually enters order items into a series of textboxes arranged in a table. The system can only provide so-many textboxes at a time (usually 5 or 10). If the user ran out of textboxes they would click an "Add more rows" button that performed a postback that was caught by that button's server-side .Click

need info about mvc and other related things


do you think mvc is an three tier architecture 

please any one explain me what is MVC , what is the use of mvc and what i need to learn the MVC, what are the initial requirements for the Learning and MVC is a three tier architecture or not.  please give me a clean explanation please  

please provide me a clean explanation where we use MVC, and why we go for MVC and what is the use of it and why it has implemented please 

Install problems - think I've messed things up!



I'm trying to install the express 2008 R2 version.  I have successfully installed this programme once but realised my predecessor had already installed a previous version.  When I opened my version, everything was setup already so I thought I'd just uninstall everything and install again.

3 hours later and I'm no closer to finding a solution.  I had issues where I couldn't delete files as they were being used.  I overcame this and thought I'd managed to delete everything but I don't think I have.

When I try to install using setup again, nothing seems to be happening.  Here is a copy of the log - please help!!

Thanks in advance.


2010-10-11 12:40:21 Slp: Log provider 'Microsoft.SqlServer.Chainer.Infrastructure.LogProviderFile' has been registered
2010-10-11 12:40:21 Slp: Log provider 'Microsoft.SqlServer.Chainer.Infrastructure.LogProviderStatus' has been registered
2010-10-11 12:40:22 Slp: Reading XML resource 'Microsoft.SQL.Chainer.PackageData.Package.xml'
2010-10-11 12:40:22 Slp: Reading schema resource 'Microsoft.SQL.Chainer.Package.Package.xsd'
2010-10-11 12:40:22 Slp: Document 'Microsoft.SQL.Chainer.PackageData.Package.xml' validated with schema 'Microsoft.SQL.Chainer.Package.Package.xsd' has been successfuly loaded into datastore path '/Datastore/Package'

Why do things not align the same way in different table styles?


So I have added a 2 column table into a team site where I am listing some documents and when the Table Style is the default "light" everything aligns at the top of the table, but if I chose the "Clear" style things no longer align to the top of the cells, same with the other options.  This is very annoying as there are no controls that would allow you to change the alignment.  I love the new functionality but it seems like it was released half baked, something like having either all the styles use the same alignment or allowing the alignment to be adjusted really is something that should be dealt with quickly.

I am sure there are HTML, or other code solutions to this issue but if you are going to put things out there in the controls they you need to either have them function correctly without adjusting code (cause 2010 loves to screw with any adjustments to code so much) or not have the features included until they are fully functional.


Disposing a SqlConnection (ADO.NET)


Hello guys,

I had a question relating to the disposal of a SQL connection. I have some code that checks whether a certain database is present on a SQL Server instance. This code is being called in an installer, so what I actually want it to do is ensure that there isn't already a database on the server with the same name than the one that will be created in the installer. If such a database exists, the user will be notified so that he can remove the database manually, and then click OK or something to let the installer proceed. I extracted the relevant piece of code. This snippet can be used in a console application to reproduce the problem:

static void Main(string[] args)
 		string connectionString = "Data Source=.;Initial Catalog=MyDatabase;User Id=MyUser;Password=MyPassword;";

		using (SqlConnection connection = new SqlConnection(connectionString))

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend