private void makeConnection()
{
Console.WriteLine("\\nBegin connecting...");
mdfFilename = "Database1.accdb";
outputFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
attachDbFilename = Path.Combine(outputFolder, mdfFilename);
connString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + attachDbFilename;
connection = new OleDbConnection(connString);
//kalo menggunakan using block,
//maka koneksi akan otomatis closed pada akhir using block,
try
{
connection.Open();
Console.WriteLine("Connected..");
Console.WriteLine("ServerVersion: {0}", connection.ServerVersion);
Console.WriteLine("State: {0}", connection.State);
Console.WriteLine("ConnectionString: {0}", connection.ConnectionString);
is_connecting = true;
}
catch (Exception ex)
{
Console.WriteLine("Failed to Connect::" + ex.Message);
}
}
private void closeConnection()
{
if (is_connecting == true)
{
Console.WriteLine("\\nClosing connection...");
connection.Close();
}
}