When connecting to a database, is it best to use one SqlConnection object for the entire server, or use one for each connection? I couldn't find a good answer in Google, but maybe my Google-fu isn't good enough.

If you're expecting methods in the class to work together within the timeout period then you can use one object, but be prepared to reopen it as necessary. The problem is that the timeout defaults to 15 seconds, so it's not like you can open a connection in the constructor of your server object and expect it to remain pristine for life.

But it's also not a great idea to open a new connection every time you want to run a SQL command. A balance is important, but it's hard to say what the balance is for your application.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.