Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi all,

 

I am interested in finding out how individuals communicate with their database in terms of opening & closing connections, and passing parameters and commands.

 

Mike55.

A Client refers to the person who incurs the development cost.

A Customer refers to the person that pays to use the product.

------

My software never has bugs. It just develops random features. (Mosabama vbforums.com)

Posted

I try and use parameters, to avoid the possibility of SQL injection attacks.

 

It's good practice as well to assume your client will be compromised (it's easy to reverse engineer a .net application) and someone will write an application to connect to your database, bypassing your client completely. To reduce the damage that could be done if a malicious application called your stored procedures with their own parameters, it might be worth validating things on the SQL side of things as well as the client and rejecting anything that looks suspicious.

 

Regards

Richard

  • Administrators
Posted

I would always use stored procs if the DB supported them and parameterised queries otherwise. Parameters / arguments should always be validated at every public entrypoint (i.e. each layer in your infrastructure) to reduce the chance of exploits etc.

Rather than lots of explicit coding I would usually create a DataAccess layer to encapsulate the db specific stuff (either write my own or more likely go to http://www.microsoft.com/patterns and look at either the DataApplication block or the EnterpriseLibrary).

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Cool, thanks for the replys. Out of interest, how do you handle to opening and closing of new connections, i.e. do you open one connection at the start and continue to pass that connection around the application for each user, or alternatively do you open and close a new connection as you require them?

 

Mike55

A Client refers to the person who incurs the development cost.

A Customer refers to the person that pays to use the product.

------

My software never has bugs. It just develops random features. (Mosabama vbforums.com)

  • Administrators
Posted
I would open a connection when I need it and close it as soon as I have finished, this lets .Net handle things like connection pooling more effectively. Keeping connections open 'in case I need it later' is usually more of a performance hit than opening them as and when you need them.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

I open and close the connection each time, wrapping it in a c# using block, using exactly the same connection string each time.

 

Connection pooling works behind the scenes to optimise performance, and if opening and closing connections is kept close to where the data is being used, any problems with connections are easier to find and debug.

Posted

I rarely disagree with PlausiblyDamp, but I wouldn't recommend the DataApplication block or anything out of Enterprise Library. It's extremely bloated and the new version will try to write an entry into the registry if it wasn't installed on the host machine (the error handling block) - which won't happen on a shared environment - trust me, learned that one by experiance.

 

Also I wrote my own DataApplication block which doesn't have all the nice GUI for the config file, but provides a (IMHO) better factory pattern (one that follows the GoF pattern) and is only about 1/10th the size of an assembly.

 

Definitely agree though to use a seperate data access layer.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...