Last active
August 29, 2015 13:56
-
-
Save f2face/8848083 to your computer and use it in GitHub Desktop.
[C#] Class koneksi dengan MySQL Connector for .NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Persiapan : | |
* Download MySQL Connector for .NET di http://dev.mysql.com/downloads/connector/net/ | |
* Add reference file "mysql.data.dll" ke project ente (pilih yang sesuai versi .NET Framework yang ente pake di project). | |
*/ | |
/*----------------------------------------------------------------------------------------- | |
* Jangan lupa: | |
using MySql.Data.MySqlClient; | |
*/ | |
class DBConnection | |
{ | |
string DB_Host = "localhost"; | |
string DB_Port = "3306"; | |
string DB_User = "root"; | |
string DB_Pass = ""; | |
string DB_Name = "nama_database_ente"; | |
public MySqlConnection Buka_Koneksi() | |
{ | |
try | |
{ | |
MySqlConnection conn = new MySqlConnection("SERVER=" + this.DB_Host + "; PORT=" + this.DB_Port + "; DATABASE=" + this.DB_Name + "; UID=" + this.DB_User + "; PASSWORD=" + this.DB_Pass + ";"); | |
conn.Open(); | |
return conn; | |
} | |
catch | |
{ | |
throw; | |
} | |
} | |
} | |
/*----------------------------------------------------------------------------------------- | |
* Penggunaan : | |
MySqlConnection conn = new DBConnection().Buka_Koneksi(); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment