vb.net - Global database connection in .net -


I inherited an application that uses a global database sqlconnection object to access the database from each form in the application is. The connection starts when the application starts.

I think the connection is not always good practice and I like to change it, so I open the database connection and turn it off every time I need to use the database.

So I would like to know if I am right.

Instead of this, I will use it, any suggestions for improvement are welcome:

  The Public Sub-update Database (Skel Commands) In the form, try the command as new SqlConnection (connectionString) by using the connection as in the form of double-form, byRef DescError string). Execute Nano () command.Dispose () NumError = 0 DescError = "" Capture as Exchange NumError = Err.Number DescError = Err.Description End End End End Try Using Sub   

I send the SqlCommand object in the method instead of a query string because I can add the parameter to a SqlCommand object.

The way you are handling the connection w Ith using a OK and connections will always be closed and will be settled for you.

Not really that the way you pass the command from the caller, there is no database engine isolation. For the parameter you can simply pass a list of names and values ​​and above your You can add parameters to the class and not 100,000 places, where you call this code.

Do not forget to associate the newly opened connection, or it will not work for the command.

Some people have even used one more command around the command so that the command can be settled, inside the use of the connection ...

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -