Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void makeConnection(){
- Console.WriteLine("\nBegin connecting...");
- mdfFilename = "Database1.mdf";
- outputFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
- attachDbFilename = Path.Combine(outputFolder, mdfFilename);
- connString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=" + attachDbFilename + ";Integrated Security=True";
- connection = new SqlConnection(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();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement