Skip to content

Instantly share code, notes, and snippets.

@f2face
Last active August 29, 2015 13:56
Show Gist options
  • Save f2face/8848083 to your computer and use it in GitHub Desktop.
Save f2face/8848083 to your computer and use it in GitHub Desktop.
[C#] Class koneksi dengan MySQL Connector for .NET
/* 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