Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 146743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:39:27+00:00 2026-05-11T08:39:27+00:00

Background: I’m rewriting a VB6 app that used MS Access for data storage to

  • 0

Background: I’m rewriting a VB6 app that used MS Access for data storage to one that uses VB.NET and MS SQL Server.

I’m curious as to the best way to pass a connection among the different forms in my application that need a connection to the database. Right now I’ve built a class to manage the connection string to pass that between forms in a secure manner:

Public Class LoginCredientials     Private uname As String     Private password_hash() As Byte = {0}     Private server_name As String  'not used in access style databases     Private dbname As String     Private st As ServerType  'enum that would allow for different connections     Private tdes As TripleDES 'encryption class to encrypt password in memory      Public Sub New()         uname = ''         server_name = ''         dbname = ''         st = ServerType.stNotDefined     End Sub     Public Sub New(ByVal Username As String, _                    ByVal Password As String, _                    ByVal ServerName As String, _                    ByVal DatabaseName As String, _                    ByVal ServType As ServerType)         tdes = New TripleDES         uname = Username         password_hash = tdes.Encrypt(Password)         server_name = ServerName         dbname = DatabaseName         st = ServType        tdes = Nothing     End Sub      Public ReadOnly Property Server_Type() As ServerType         Get             Return st         End Get     End Property     Public ReadOnly Property CompanyName() As String         Get             Return dbname.Remove(0, 4)         End Get     End Property     Public Property UserName() As String         Get             Return uname         End Get         Set(ByVal value As String)             uname = value         End Set     End Property     Public Property Password() As String         Get             tdes = New TripleDES             Return tdes.Decrypt(password_hash)             tdes = Nothing         End Get         Set(ByVal value As String)             tdes = New TripleDES             password_hash = tdes.Encrypt(value)             tdes = Nothing         End Set     End Property     Public Property ServerName() As String         Get             Return server_name         End Get         Set(ByVal value As String)             server_name = value         End Set     End Property     Public Property DatabaseName() As String         Get             Return dbname         End Get         Set(ByVal value As String)             dbname = value         End Set     End Property      Public Function GetConnectionString() As String         Dim cstring As String = ''         tdes = New TripleDES         Select Case st             Case ServerType.stSQLServer                 cstring = 'User ID=' & uname & ';' & _                         'Password=' & tdes.Decrypt(password_hash) & ';' & _                         'Initial Catalog=' & dbname & ';' & _                         'Data Source=' & server_name         End Select         tdes = Nothing         Return cstring     End Function End Class

I had been passing a reference to my object to any of my forms that needed a connection to the database like so:

'in the form declaration Private myLC As LoginCredientials Public Sub New(ByRef lc As LoginCredientials)     InitializeComponent()     myLC = lc End Sub

And then I would create a new connection object, did what I needed to do, and then closed the connection and destroyed the connection object. When I’ve done this before long ago in ADO with VB6, the process created by the connection was killed when the connection object was destroyed, but that doesn’t appear to be the case anymore. Now every time I create a new connection object and connect to my server, a new process is created and then put to sleep when I close my connection. After a while the server will start refusing connections until I log in and kill all the processes my app created. Obviously this isn’t being done right, and I would like to learn the right way.

Would it be better to simply pass the same connection object by reference (or inside a wrapper class) among my forms, leaving the connection object open?

What is the correct way to close my connection so that I don’t eventually get a bunch of sleeping processes on my SQL server? Is there a setting in SQL server I can adjust to automatically kill processes after a certain period of inactivity?

Would you consider encrypting the password in runtime memory overkill?

Thank you for any help. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T08:39:28+00:00Added an answer on May 11, 2026 at 8:39 am

    You should NOT pass the connection object among forms. Basically, the pattern when using a connection to SQL Server is to create the connection, open it, perform your operation, then close the connection.

    To that end, you should have a public static method somewhere which will generate your SqlConnection which you would use in a Using statement, like so:

    Using connection As SqlConnection = GetConnection     ' Use connection here.  End Using 

    That should prevent the processes from stacking up on the server.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 96k
  • Answers 96k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I decided to to read a boolean (keep alive) in… May 11, 2026 at 7:09 pm
  • Editorial Team
    Editorial Team added an answer "What are some warning signs from a developer's perspective that… May 11, 2026 at 7:09 pm
  • Editorial Team
    Editorial Team added an answer Found one - LockHunter May 11, 2026 at 7:09 pm

Related Questions

Background: I have a little video playing app with a UI inspired by the
Background: I need to reserve an amount of memory below 0xA0000 prior to my
Background I am writing and using a very simple CGI-based (Perl) content management tool
Background I have a massive db for a SharePoint site collection. It is 130GB
Background I am trying to create a copy of a business object I have

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.