Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27240

VS 2012 Showing the Connecting.State string on a label

$
0
0
Hi again everyone.
I've come back with another problem that is driving me nuts ..

I need a statusstriplabel to display the following states of an SQL DataBase connection:

Online
Connecting
Broken
Closed

I'm able to display the 1st and last states on the label with no problem, but I need the Connecting state to display on the label aswell... but for the life of me I just can't get it to display, I don't know if it's because the connection is so fast, that that state doesn't have enough time to display, but I don't think that is the problem, because I'm forcing a thread sleep and the state just changes from Closed to Online in 1000ms

This is the code for the routine:

Code:

Public Sub _sqlConnection(ByVal ConState As ToolStripStatusLabel, ByVal SubMenu As ToolStripItem, ByVal MenuAbas As TabControl)
        If _minhaLigacaoSQL.State = ConnectionState.Closed Then
            _minhaLigacaoSQL.ConnectionString = _connectionString
            _minhaLigacaoSQL.Open()
            MenuAbas.Enabled = True
            ConState.Text = _minhaLigacaoSQL.State.ToString()
            ConState.ForeColor = Color.Green
            SubMenu.Text = "Disconnect from DB"
        ElseIf _minhaLigacaoSQL.State = ConnectionState.Connecting Then
            ConState.Text = _minhaLigacaoSQL.State.ToString()
            ConState.ForeColor = Color.Yellow
        ElseIf _minhaLigacaoSQL.State = ConnectionState.Broken Then
            ConState.Text = _minhaLigacaoSQL.State.ToString()
            ConState.ForeColor = Color.DarkRed
        ElseIf _minhaLigacaoSQL.State = ConnectionState.Open Then
            _minhaLigacaoSQL.Close()
            MenuAbas.Enabled = False
            ConState.Text = _minhaLigacaoSQL.State.ToString()
            ConState.ForeColor = Color.Red
            SubMenu.Text = "Connect to DB"
        End If
    End Sub

And this is the code for the StatusStripItem when I press it:

Code:

Private Sub ConnectToDBToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ConnectToDBToolStripMenuItem.Click   
        Try
            Me.Cursor = Cursors.WaitCursor
            UseWaitCursor = True
            Threading.Thread.Sleep(1000)
            _utils._sqlConnection(tssConnectionStatus, ConnectToDBToolStripMenuItem, TabControl1)
            UseWaitCursor = False
            Me.Cursor = Cursors.Default
        Catch _error As Exception
            Dim _txtError As String = "Erro:" + _error.Message + Environment.NewLine + "Deseja Sair do Formulário?"
            Dim result As DialogResult = MessageBox.Show(_txtError, "Aviso", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
            If result = DialogResult.OK Then
                Application.Exit()
            End If
        End Try
    End Sub

I've done several changes on my code and I just get led to the same result over and over x.x
May anyone please tell me what I need to change or add in my code?

Viewing all articles
Browse latest Browse all 27240

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>