I am testing and I have found an error...
When I have the database ignited shows to me that it is connected but I extinguish it says to me that is connected (it would have to say to me that it is disconnected).
Another serious error, having the database extinguished, I open the application and when trying to connect closes the program, error: NullReferenceException.
The code is the following one:
In module:
Code: Select all
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.Windows.Forms
Imports System.Data
Imports System.Data.Common
Imports System.IO
Imports System.Runtime.InteropServices
Imports CoreLab.MySql
Module basPublico
Public conn As New MySqlConnection("User ID=root;Password=;Host=192.168.0.1;Port=3306;Database=k008;")
Public Sub ArrancarConexion()
Try
conn.Open()
MsgBox("Ok!", MsgBoxStyle.Information, "")
Catch ex As MySqlException
MsgBox(ex.Message, MsgBoxStyle.Critical, "")
End Try
End Sub
End Module
In Form:
Code: Select all
Public Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
#Region " Código generado por el Diseñador de Windows Forms "
Public Sub New()
MyBase.New()
'El Diseñador de Windows Forms requiere esta llamada.
InitializeComponent()
'Agregar cualquier inicialización después de la llamada a InitializeComponent()
End Sub
'Form reemplaza a Dispose para limpiar la lista de componentes.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub
'NOTA: el Diseñador de Windows Forms requiere el siguiente procedimiento
'Puede modificarse utilizando el Diseñador de Windows Forms.
'No lo modifique con el editor de código.
Friend WithEvents Button2 As System.Windows.Forms.Button
Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(32, 88)
Me.Button1.Size = New System.Drawing.Size(176, 56)
Me.Button1.Text = "Conect"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(96, 216)
Me.Button2.Text = "Exit"
'
'Form1
'
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Menu = Me.MainMenu1
Me.Text = "Form1"
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ArrancarConexion()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Application.Exit()
End Sub
End Class
A greeting