public DatabaseVersion Upgrade(string oldDbFile) { //ISession session=NHibernateSessionManager.SessionFactory.OpenSession(); using (var scope = new SessionScope()) { //var transaction = session.BeginTransaction(); try { Log.WriteInfo("DatabaseUpdater11To20. OldFile={0}", oldDbFile); if (File.Exists(oldDbFile)) { Log.WriteInfo("File exists. Start converting db from 1.1.0.1 to 2.0.0.0"); importProfiles(oldDbFile); } Log.WriteInfo("Set database version to 2.0.0.0"); DatabaseVersion version = new DatabaseVersion("2.0.0.0"); //session.SaveOrUpdate(version); version.Create(); //transaction.Commit(); Log.WriteInfo("DatabaseUpdater11To20. Everything is ok"); return(version); } catch (Exception) { //transaction.Rollback(); throw; } finally { //session.Close(); } } }
public DatabaseVersion Upgrade(string oldDbFile) { using (var scope = new TransactionScope()) { Log.WriteInfo("DatabaseUpdater20To30. OldFile={0}", oldDbFile); if (File.Exists(oldDbFile)) { Log.WriteInfo("File exists. Start converting db from 2.0.0.0 to 3.0.0.0"); SqlCeConnection oldConnection = new SqlCeConnection(string.Format("Data Source={0};", oldDbFile)); Log.WriteInfo("Start migration"); oldConnection.Open(); Log.WriteInfo("Connection opened"); SqlCeCommand cmd = new SqlCeCommand(); cmd.Connection = oldConnection; cmd.CommandText = "ALTER TABLE A6WEntry ADD MyTraining_id uniqueidentifier"; } Log.WriteInfo("Set database version to 3.0.0.0"); DatabaseVersion version = new DatabaseVersion("3.0.0.0"); version.Create(); scope.VoteCommit(); Log.WriteInfo("DatabaseUpdater20To30. Everything is ok"); return(version); } }
public DatabaseVersion Upgrade(string oldDbFile) { using (var scope = new TransactionScope()) { Log.WriteInfo("DatabaseUpdater20To30. OldFile={0}", oldDbFile); if (File.Exists(oldDbFile)) { Log.WriteInfo("File exists. Start converting db from 2.0.0.0 to 3.0.0.0"); importProfiles(oldDbFile); } Log.WriteInfo("Set database version to 3.0.0.0"); DatabaseVersion version = new DatabaseVersion("3.0.0.0"); version.Create(); scope.VoteCommit(); Log.WriteInfo("DatabaseUpdater20To30. Everything is ok"); return(version); } }