Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

2 unrelated questions

1)

I thought that .NET was supposed to automatically take care of sharing SQL connections for you.  I found however that if I didn't individually close all connections programmatically, the database would run out of connections.

So, I went in and put close statements everywhere I could find open statements.

-Is .NET supposed to take care of this? and
-Is there a CloseAllOpenConnections command I can just run before the response gets sent back to the client?

2)

I use VS.NET to develop my C# web forms.  When i think everything is working, I try copying just the following files:

-filename.aspx
-filename.aspx.cs
-filename.aspx.resx

-global.asax
-global.asax.cs
-global.asax.resx

-web.config

into the virtual directory on the server.

This doesn't work, but when I also copy all the _vti and bin directories, then things work.

My naive hope is that even though I develop with VS.NET, I just want to copy over the text files as though I created them in Notepad.

That way, IIS can compile them for whatever version of the .NET framework it has installed.  And later, if I update the files, IIS will recompile them for me.


Thanks

Charles

Charles Reich
Thursday, July 03, 2003

1) No - it's definitely not supposed to do this. .NET automatically manages *memory* it knows about-- it frees it when it needs to. But when it comes to external resources like db connections, GDI handles or anything else external then you don't want to leave the freeing of the resources to "non-deterministic finalization" (it'll do it eventually but not soon enough). Basically, anything that has a Close() or Dispose() method should have it called by you explicitly in somewhere like a "finally" block. In fact the Dispose method is part of an interface called IDisposable which is supported by the "using" keyword in C# -- look it up.

2) You only need to copy:
    - web.config and
    - *.aspx and
    - everything in the /bin folder
Note you don't need to deploy your precious source code.

I suggest you work through the docs starting at:
.NET Framework SDK > .NET Framework > Building Applications > Creating ASP.NET Web Applications

Duncan Smart
Thursday, July 03, 2003

1. .NET does connection POOLING, not connection SHARING. That means you need to tell it when you're done w/ the connection (aka, close it), so that it can go back in the pool.

2. By default, code behind files are compiled when you hit the Build menu option, and the bin directory contains compiled versions of these files. If you'd rather have the system compile the .cs files dynamically in addition to the .aspx files, then: (a) change the "CodeBehind=" attributes in the .aspx files into "src=" attributes, and (b) right click on the .cs files, do Properties, and change their action from "Compile" to "Content".

Brad Wilson (dotnetguy.techieswithcats.com)
Friday, July 04, 2003

Oh, and when you've done all that, make sure to delete the DLL from your bin directory, or you'll get compilation errors.

Brad Wilson (dotnetguy.techieswithcats.com)
Friday, July 04, 2003

Thanks Brad & Duncan.  All very helpful information!

Charles Reich
Sunday, July 06, 2003

*  Recent Topics

*  Fog Creek Home