There are quite a few open source gallery out there that's exactly as you described.
Coppermine came to mind, although it was LAMP (Linux, Apache, MySQL, PHP) but the concept is similar if you want to download and play with it.
If you don't want to write your own database abstraction layer, there are a few really good MVCs (Model View Control) out there that helps with it. Unfortunately most are LAMP, but you can peek at it to get a good idea of what's there to use instead of writing your own. If you can google something similar for MS products, you can avoid a lot of security problems & shorten your dev time substantially.