4 ms·
Just going off the top of my head: This much work should not be happening in a button's click event handler. It should be its own method (or more than one!) ca
by funkah 15y ago
Just going off the top of my head:
This much work should not be happening in a button's click event handler. It should be its own method (or more than one!) called by the click handler.
For that matter, data access should be handled by a DAO, front end code should be calling a service or gateway rather than going to the DB itself. Way too much is happening in GUI code.
In a "real" app, the connection string would be configured in some way, not just a local variable.
The way the query is written is wide open to SQL injection. Nobody should be writing SQLI vulns in this day and age, ever. In .NET land, if you're still concatenating queries instead of using query parameters, you should go home because you are bad at your job.
The list could go on. Some of this can be excused by the fact that it's from an interviewee and not part of a "real" app. But the SQLI is just a huge red flag, to me. One thing they did get right: wrapping the connection object in a "using" block so it is guaranteed to be disposed of correctly.
- artmageddon 15y ago>One thing they did get right: wrapping the connection object in a "using" block so it is guaranteed to be disposed of correctly. True, but the page redirect happens within the using block. I would assume that the disposal still happens, but this is very very bad form.
- funkah 15y agoGood point. I'm about 95% sure the disposal would still happen, but I agree it's bad form. This code is terrible in so many ways I didn't even consider that.
- JonoW 15y agoThat code is filled with all sorts of horrors (Sql injection, passwords in plain-text in DBs, passwords sent in query-string, all logic in web-layer), but redirecting in a using block is ok, the disposers will always be called (outside of fatal exceptions like StackOverflows)
- city41 15y agousing is syntactic sugar for a try/finally block with a Dispose call in the finally. So yes, the dispose will still happen.