Avatar of rwheeler23
rwheeler23
Flag 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.
Microsoft SQL Server 2008C#

Avatar of undefined
Last Comment
rwheeler23

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
b_levitt

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Peter Chan

Try to put this
      
<connectionStrings>
		<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"/>
	</connectionStrings>

Open in new window


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

ASKER
Thanks. This is how I will proceed.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck