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

  • SEARCH
  • Home
  • 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 6796849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:32:14+00:00 2026-05-26T18:32:14+00:00

In the first form I will load Tabels in the secound I want to

  • 0

In the first form I will load Tabels in the secound I want to open the DB Connection.

I wrote a Class which enables me to open and close the connection

Imports System
Imports System.Data
Imports MySql.Data.MySqlClient

Public Class DBConn


Dim conn As New MySqlConnection
Dim connString As String

Dim DataSchnitstelel As MySqlDataAdapter


Public Function verbindungString(ByVal Server As String, ByVal UID As String, ByVal PWD As String, _
                                 ByVal Datenbank As String)
    connString = "server=" & Server & ";uid=" & UID & ";pwd=" & PWD & ";database=" & Datenbank & ";"



    connString = CStr(connString)
End Function



Public Sub Open()
    conn.ConnectionString = connString
    Try
        conn.Open()
        MsgBox(connString)
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
End Sub



Public Function Close()
    If conn.State = ConnectionState.Open Then
        Try
            conn.Close()
            MessageBox.Show("Closed!")
        Catch ex As Exception
            MessageBox.Show("Something Wrong" & ex.Message)
        End Try
    Else
        MessageBox.Show("Verbindung bereitsgeschlossen")
    End If
End Function


Public Function UpdateStatus()
    Dim Klank As Boolean
    If conn.State = 1 Then
        Klank = True
    End If
    If conn.State = 0 Then
        Klank = False
    End If
    Return Klank
End Function

Public Function SQLSelect()

End Function

End Class

In the Second Form i Connect to the DB.
The connection opens successfully but it’s not open in the first form 🙁

Whats Wrong?

  • 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. Editorial Team
    Editorial Team
    2026-05-26T18:32:14+00:00Added an answer on May 26, 2026 at 6:32 pm

    I guess the problem is that you use in both forms somewhere

    Dim bla as New DBConn
    

    Instead that, you can make use of the Singleton Pattern. Add the following code inside your DBConn class:

    'Make Constructor Private to disallow creating an Instance from somewhere else
    Private Sub New()
    End Sub
    
    'Variable to share the only created instance
    Private Shared _Instance As DBConn
    
    'Function to get access to the only instance
    Public Shared ReadOnly Property Instance() As DBConn
      Get
        If _Instance Is Nothing Then
          _Instance = New DBConn
        End If
        Return _Instance
      End Get
    End Property
    

    After those changes, you need to ‘correct’ one line in each form to the following:

    Dim bla as DBConn = DBConn.Instance
    

    This should assure that both forms are asking for an instance, and only the very first time an instance is created. All further askings receive the same instance.

    One more thing: If you have ‘WithEvents’ or any EventHandling connected to that Singleton, then make sure to set your DBConn variable to nothing when you close/dispose form1. But according to your code this does not matter.

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

Sidebar

Related Questions

I want to make a user-registration form where I will have fields such first
I am new to Qt I created my first form and I want to
I want to create a simple user registration form with First / Last name,
In C# Winforms, while user first load the form, I get the input as
I have a form of radio check boxes (yes/no), which I want to have
I have a MOSS workflow where on the first form, the user can choose
Basically I just need the id of the record on the first form so
I have two forms. The first form is the mainForm, this never goes anywhere.
I have 2 forms set up. In the first form I have the following
I've been putting together my first Ajax powered form ( here ), with the

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.