private static void MakeDBDetach() { //creates a db attacher instance SQLServerDBAttacher dbatt = new SQLServerDBAttacher(sqlServerName, UserId, password); //starts the attach DB process string msgStr = ""; msgStr = "Removing Data Base [" + DBName + "] from server [" + sqlServerName + "] . . . "; Console.WriteLine(); Console.WriteLine(msgStr); try { dbatt.Detach(DBName, true); Console.WriteLine("Database removed succesfully."); } catch (Exception ex) { Console.WriteLine("ERROR : " + ex.Message); } finally { if (!(dbatt == null)) { dbatt.Dispose(); } } }
private static void MakeDBAttachment() { //creates a db attacher instance SQLServerDBAttacher dbatt = new SQLServerDBAttacher(sqlServerName, UserId, password); //starts the DB attachment process string msgStr; msgStr = "Installing Data Base [" + DBName + "] on server [" + sqlServerName + "]"; Console.WriteLine(); Console.WriteLine("Installing database..."); try { if (ldfFilePathName.Length <= 0) { dbatt.Attach(DBName, mdfFilePathName); } else { dbatt.Attach(DBName, mdfFilePathName, ldfFilePathName); } Console.WriteLine("Database installed successfully."); } catch (Exception ex) { Console.WriteLine("ERROR : " + ex.Message); } finally { if (!(dbatt == null)) { dbatt.Dispose(); } } }