Make a Connection From VB.Net to MySQL - Gudio Tutorial

    Social Items


Make a Connection From VB.Net to MySQL
Make a Connection From VB.Net to MySQL - Logo

Make a Connection From VB.Net to MySQL
In this article, I will give you a tutorial, how to make a database connection from visual studio vb.netto mysql with mysql connection.

Hello everyone, come back with me in Gudio Tutorial. This Gudio blog is a personal blog that I created, which discusses the programming of desktop, website and mobile applications. As well as discussing blog tips and around Android and others.

Before we proceed to the discussion topic. Maybe there are some of you who don't know visual studio and mysql. As always, in every tutorial article, I always start with definitions, before discussing the topic. I will give a definition, what is Visual Studio? and what is MySQL?



What is Visual Studio ?

Microsoft Visual Studio is a software, which can be used to develop applications, such as console applications, Windows applications, or Web applications.

Microsoft Visual Studio can be used to develop applications in native code or managed code. In addition, Visual Studio can also be used to develop Silverlight applications, Windows Mobile applications (which run on the .NET Compact Framework).


Visual Studio includes compilers, SDK, Integrated Development Environment (IDE), and documentation (generally in the form of MSDN Library). The compilers included in the Visual Studio package include Visual C ++, Visual C #, Visual Basic, Visual Basic .NET, Visual InterDev, Visual J ++, Visual J #, Visual FoxPro, and Visual SourceSafe.



What is Visual Basic.Net (VB.Net)

According to wikipedia, Visual Basic .NET (VB.NET) is a multi-paradigm, object-oriented programming language, implemented on the .NET Framework. Microsoft launched VB.NET in 2002 as the successor to its original Visual Basic language. Although the ".NET" portion of the name was dropped in 2005, this article uses "Visual Basic [.NET]" to refer to all Visual Basic languages released since 2002, in order to distinguish between them and the classic Visual Basic. Along with Visual C#, it is one of the two main languages targeting the .NET framework.

Microsoft's integrated development environment (IDE) for developing in Visual Basic .NET language is Visual Studio. Most Visual Studio editions are commercial; the only exceptions are Visual Studio Express and Visual Studio Community, which are freeware. In addition, the .NET Framework SDK includes a freeware command-line compiler called vbc.exe. Mono also includes a command-line VB.NET compiler.
 


What is MySQL ?

According to wikipedia, MySQL is a multi-level, multi-user SQL database management system or DBMS, with around 6 million installations worldwide. MySQL AB makes MySQL available as free software under the GNU General Public License (GPL), but they also sell under commercial licenses for cases where its use does not match the use of GPL.

Unlike projects such as Apache, where software is developed by the general community, and the copyright for the source code is owned by their respective authors, MySQL is owned and sponsored by a Swedish commercial company MySQL AB, which holds the copyright almost to all the source code. The two Swedes and one Finnish who founded MySQL AB are: David Axmark, Allan Larsson, and Michael "Monty" Widenius.


in the MySQL programming language, there are several APIs (Application Programming Interfaces) available that allow computer applications written in various programming languages to be able to access MySQL databases including: C programming language, C ++, C #, Eiffel programming language, Smalltalk programming language , Java programming language, Lisp programming language, Perl, PHP, Python programming language, Ruby, REALbasic and Tcl. An ODBC interface calls MyODBC which allows every programming language that supports ODBC to communicate with the MySQL database. Most MySQL source code in ANSI C. 

The following features and capabilities possessed by MySQL:
  1. High performance in processing simple queries, in the sense that it can process more SQL per unit time.Has more data types such as: signed / unsigned integer which has a data length of 1,2,3,4 and 8 bytes, FLOAT, DOUBLE, CHAR, VARCHAR, TEXT, BLOB, DATE, TIME, DATETIME, TIMESTAMP, YEAR, SET and type ENUM.
  2. Supports indexed fields, with a maximum of 32 indexes in one table. *
  3. MYSQL has several layers of security, such as subnet masks, host names, and user access permissions with detailed licensing systems and encrypted passwords.
  4. Connectivity, MySQL can connect with clients using TCP / IP protocol, Unix socket (UNIX), or Named Pipes (NT).
  5. Multi-user. MySQL can be used by several users at the same time without experiencing problems or conflicts
  6. Command and function, MySQL has full functions and operators that support select and where in query commands.
  7. Structure Table, MySQL has a table structure that is more flexible in handling ALTER TABLE than other DBMS.
  8. Full support for SQL GROUP BY and ORDER BY sentences. Supports full functions (COUNT (), COUNT (), DISTINCT () AVG (), STD (), SUM (), MAX () and MIN ())

VB.Net Connection to MySQL

Before starting how to connect, make sure you have all the equipment, such as:
  1. VB.Net (programming language)
  2. Xampp for windows, download this application here.
  3. or you can also use the alternative link below:
  4. And the most important is the mysql net connector. Because without this, you will not be able to connect. This software, you can download here.
I assume you have installed all the needs above. First, you open your VB.Net application, then add references by going to the project menu:
  1. Add reference
  2. Click the .Net tab
  3. Then look for "mysql.data" (if you have installed the mysql net connector, the choice of mysql data is definitely there).
Make a Connection From VB.Net to MySQL
If so, click ok. Here I share only the module for the connection (not a complete application), so add the module in your application and type the following code: 
Imports MySql.Data.MySqlClient.MySqlConnection
Module modKoneksi
       Public conn As New MySql.Data.MySqlClient.MySqlConnection
       Public Sub koneksi(ByVal server As String, ByVal user As String, ByVal pass As String, _
                           ByVal db As String, ByVal port As String)
            Try
                If conn.State = ConnectionState.Closed Then
                   conn.ConnectionString = "DATABASE=" & db _
                    & ";SERVER = " & server _
                    & ";user id=" & user & ";password=" & pass & ";port=" & port & ";charset=utf8"
                    conn.Open()
                End If
            Catch ex As MySql.Data.MySqlClient.MySqlException
                MsgBox("Koneksi ke server gagal")
            End Try
        End Sub
        Public Sub disconnect()
            Try
                conn.Open()
            Catch ex As MySql.Data.MySqlClient.MySqlException
            End Try
        End Sub
End Module

I have tried this module myself and I have tested it 100% work. So if you fail to make connections, make sure:
  1. the code you wrote is correct in terms of connection from this module.
  2. You have created the MySQL database.
  3. Also note the username, password, the host in the database is it the same as the one in the connection code.
So that's the discussion about Make a Connection From VB.Net to MySQL. Next time, I will make a tutorial about the complete application.

Hopefully this article can give you all the benefits, and apologize if there are many mistakes in the words or writing in this article. Because I am still learning English. Hope you know. See you later in my next article, of course with more interesting discussions.

Make a Connection From VB.Net to MySQL


Make a Connection From VB.Net to MySQL
Make a Connection From VB.Net to MySQL - Logo

Make a Connection From VB.Net to MySQL
In this article, I will give you a tutorial, how to make a database connection from visual studio vb.netto mysql with mysql connection.

Hello everyone, come back with me in Gudio Tutorial. This Gudio blog is a personal blog that I created, which discusses the programming of desktop, website and mobile applications. As well as discussing blog tips and around Android and others.

Before we proceed to the discussion topic. Maybe there are some of you who don't know visual studio and mysql. As always, in every tutorial article, I always start with definitions, before discussing the topic. I will give a definition, what is Visual Studio? and what is MySQL?



What is Visual Studio ?

Microsoft Visual Studio is a software, which can be used to develop applications, such as console applications, Windows applications, or Web applications.

Microsoft Visual Studio can be used to develop applications in native code or managed code. In addition, Visual Studio can also be used to develop Silverlight applications, Windows Mobile applications (which run on the .NET Compact Framework).


Visual Studio includes compilers, SDK, Integrated Development Environment (IDE), and documentation (generally in the form of MSDN Library). The compilers included in the Visual Studio package include Visual C ++, Visual C #, Visual Basic, Visual Basic .NET, Visual InterDev, Visual J ++, Visual J #, Visual FoxPro, and Visual SourceSafe.



What is Visual Basic.Net (VB.Net)

According to wikipedia, Visual Basic .NET (VB.NET) is a multi-paradigm, object-oriented programming language, implemented on the .NET Framework. Microsoft launched VB.NET in 2002 as the successor to its original Visual Basic language. Although the ".NET" portion of the name was dropped in 2005, this article uses "Visual Basic [.NET]" to refer to all Visual Basic languages released since 2002, in order to distinguish between them and the classic Visual Basic. Along with Visual C#, it is one of the two main languages targeting the .NET framework.

Microsoft's integrated development environment (IDE) for developing in Visual Basic .NET language is Visual Studio. Most Visual Studio editions are commercial; the only exceptions are Visual Studio Express and Visual Studio Community, which are freeware. In addition, the .NET Framework SDK includes a freeware command-line compiler called vbc.exe. Mono also includes a command-line VB.NET compiler.
 


What is MySQL ?

According to wikipedia, MySQL is a multi-level, multi-user SQL database management system or DBMS, with around 6 million installations worldwide. MySQL AB makes MySQL available as free software under the GNU General Public License (GPL), but they also sell under commercial licenses for cases where its use does not match the use of GPL.

Unlike projects such as Apache, where software is developed by the general community, and the copyright for the source code is owned by their respective authors, MySQL is owned and sponsored by a Swedish commercial company MySQL AB, which holds the copyright almost to all the source code. The two Swedes and one Finnish who founded MySQL AB are: David Axmark, Allan Larsson, and Michael "Monty" Widenius.


in the MySQL programming language, there are several APIs (Application Programming Interfaces) available that allow computer applications written in various programming languages to be able to access MySQL databases including: C programming language, C ++, C #, Eiffel programming language, Smalltalk programming language , Java programming language, Lisp programming language, Perl, PHP, Python programming language, Ruby, REALbasic and Tcl. An ODBC interface calls MyODBC which allows every programming language that supports ODBC to communicate with the MySQL database. Most MySQL source code in ANSI C. 

The following features and capabilities possessed by MySQL:
  1. High performance in processing simple queries, in the sense that it can process more SQL per unit time.Has more data types such as: signed / unsigned integer which has a data length of 1,2,3,4 and 8 bytes, FLOAT, DOUBLE, CHAR, VARCHAR, TEXT, BLOB, DATE, TIME, DATETIME, TIMESTAMP, YEAR, SET and type ENUM.
  2. Supports indexed fields, with a maximum of 32 indexes in one table. *
  3. MYSQL has several layers of security, such as subnet masks, host names, and user access permissions with detailed licensing systems and encrypted passwords.
  4. Connectivity, MySQL can connect with clients using TCP / IP protocol, Unix socket (UNIX), or Named Pipes (NT).
  5. Multi-user. MySQL can be used by several users at the same time without experiencing problems or conflicts
  6. Command and function, MySQL has full functions and operators that support select and where in query commands.
  7. Structure Table, MySQL has a table structure that is more flexible in handling ALTER TABLE than other DBMS.
  8. Full support for SQL GROUP BY and ORDER BY sentences. Supports full functions (COUNT (), COUNT (), DISTINCT () AVG (), STD (), SUM (), MAX () and MIN ())

VB.Net Connection to MySQL

Before starting how to connect, make sure you have all the equipment, such as:
  1. VB.Net (programming language)
  2. Xampp for windows, download this application here.
  3. or you can also use the alternative link below:
  4. And the most important is the mysql net connector. Because without this, you will not be able to connect. This software, you can download here.
I assume you have installed all the needs above. First, you open your VB.Net application, then add references by going to the project menu:
  1. Add reference
  2. Click the .Net tab
  3. Then look for "mysql.data" (if you have installed the mysql net connector, the choice of mysql data is definitely there).
Make a Connection From VB.Net to MySQL
If so, click ok. Here I share only the module for the connection (not a complete application), so add the module in your application and type the following code: 
Imports MySql.Data.MySqlClient.MySqlConnection
Module modKoneksi
       Public conn As New MySql.Data.MySqlClient.MySqlConnection
       Public Sub koneksi(ByVal server As String, ByVal user As String, ByVal pass As String, _
                           ByVal db As String, ByVal port As String)
            Try
                If conn.State = ConnectionState.Closed Then
                   conn.ConnectionString = "DATABASE=" & db _
                    & ";SERVER = " & server _
                    & ";user id=" & user & ";password=" & pass & ";port=" & port & ";charset=utf8"
                    conn.Open()
                End If
            Catch ex As MySql.Data.MySqlClient.MySqlException
                MsgBox("Koneksi ke server gagal")
            End Try
        End Sub
        Public Sub disconnect()
            Try
                conn.Open()
            Catch ex As MySql.Data.MySqlClient.MySqlException
            End Try
        End Sub
End Module

I have tried this module myself and I have tested it 100% work. So if you fail to make connections, make sure:
  1. the code you wrote is correct in terms of connection from this module.
  2. You have created the MySQL database.
  3. Also note the username, password, the host in the database is it the same as the one in the connection code.
So that's the discussion about Make a Connection From VB.Net to MySQL. Next time, I will make a tutorial about the complete application.

Hopefully this article can give you all the benefits, and apologize if there are many mistakes in the words or writing in this article. Because I am still learning English. Hope you know. See you later in my next article, of course with more interesting discussions.
iklan related post
Load comments