Im starting a new project in Visual Studio as Windows Forms Application using C#. Project has login form, main form and other less important forms. All of them uses connection with mysql. Where should i place code responsible for connecting with mysql server to be able to use it in any form? I dont want to create a new connection in every single form. Any hints?
Im starting a new project in Visual Studio as Windows Forms Application using C#.
Share
Well, I wouldn’t want the UI classes to access the database directly in the first place… but you should be creating a new connection each time you interact with the database, and close it after the operation (probably with a
usingstatement). Let connection pooling handle the real underlying network connection.EDIT: See the MySQL connection pooling documentation for more information.