Link to home
Create AccountLog in
Avatar of rwheeler23
rwheeler23Flag for United States of America

asked on

VS C# Best Practice Database Connection

From a best practice performance standpoint what is the best way to set this up? I need to create a control panel that will have several options that all pertain to doing various things to a single SQL database. My question is, should I write this routine so that it opens the database connection once when the control panel is fired up or should I open the database connection within each module called and close it upon exiting?  I am not sure of the cost overhead with opening a connection and then leaving it open. I will be using VS 2010 C# to create this application.
Avatar of b_levitt

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Try to put this
		<add name="conn2" connectionString="Data Source=192.?.?.?\your_db_instance;Initial Catalog=your_db_schema;Integrated Security=False;User ID=your_db_login;Password=??????" providerName="System.Data.SqlClient"/>

Open in new window

within Web.config/app.config file in your project, to ensure the project will work fine with the database.
Avatar of rwheeler23


Thanks. This is how I will proceed.