private void DropTriggers(Database database)
		{
    		database.Execute(
    			@"DECLARE @Triggers TABLE(TriggerName VARCHAR(MAX))
				INSERT INTO
				@Triggers
				SELECT Name FROM Sys.triggers


				DECLARE @Commands TABLE (Id INT, Sql VARCHAR(MAX))
				INSERT INTO @Commands
				SELECT ROW_NUMBER() OVER(ORDER BY TriggerName), Replace('IF EXISTS (SELECT * FROM Sys.triggers WHERE Name = ''{TriggerName}'' ) DROP TRIGGER {TriggerName}', '{TriggerName}', TriggerName) FROM @Triggers



				DECLARE @Counter INT SELECT @Counter = COUNT(*) FROM @Commands
				WHILE (@Counter > 0) BEGIN
					DECLARE @Command VARCHAR(MAX)
					SELECT @Command = Sql FROM @Commands WHERE Id = @Counter
					PRINT (@Command)
					EXEC (@Command)
					SET @Counter = @Counter - 1
				END
			");
		}
        public void LoadAssemblyIntoDatabase()
        {
			SqlInstanceInfo sqlInstanceInfo = new SqlInstanceInfo(conn);
			Database database = new Database(conn);
			database.CreateDatabaseIfDoesNotExist();
			if (System.Environment.MachineName != sqlInstanceInfo.ServerName)
			{
				ClrAssemblyFile remoteClrAssemblyFile = null;
				if (directoryToCopyAssemlyTo == null)
				{
					directoryToCopyAssemlyTo = GetTempDirectoryInfo(sqlInstanceInfo.ServerName, CurrentUserNameWithoutDomain);
				}
				if (!directoryToCopyAssemlyTo.Exists)
				{
					directoryToCopyAssemlyTo.Create();
				}
				CopyFilesOverToRemoteServer(clrAssemblyFile.FileInfo.Directory, directoryToCopyAssemlyTo);
				string path = Path.Combine(directoryToCopyAssemlyTo.FullName, clrAssemblyFile.FileInfo.Name);
				remoteClrAssemblyFile = new ClrAssemblyFile(new FileInfo(path));
				UpdateAssembly(database, remoteClrAssemblyFile);
			}
			else
			{
				UpdateAssembly(database, clrAssemblyFile);
			}
			
        }
Ejemplo n.º 3
0
		public void ClrIsEnabledInDatabaseTest_ClrIsEnabled_Returns()
		{
			System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(Common.Properties.ConnectionString);
			Database di = new Database(conn);
			di.CreateDatabaseIfDoesNotExist();
			SetClrEnabled(conn, true);
			Assert.IsTrue(di.ClrIsEnabledInDatabase);
		}
Ejemplo n.º 4
0
		public void ClrIsEnabledInDatabaseTest_ClrIsNotEnabled_ReturnsFalse()
        {
			
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(Common.Properties.ConnectionString);
			Database di = new Database(conn);
            SetClrEnabled(conn, false);
            Assert.IsFalse(di.ClrIsEnabledInDatabase);
        }
    	private void UpdateAssembly(Database database, ClrAssemblyFile assembly)
    	{
    		try
    		{
				database.UpdateAssembly(assembly);
    		}
    		catch (Exception ex)
    		{
    			if (ex.Message.Contains("was not found with the same signature in the updated assembly"))
    			{
    				DropTriggers(database);
					database.RemoveAssembly(assembly);
					database.UpdateAssembly(assembly);
    			}
    			else
    			{
    				throw;
    			}
    		}
    	}
Ejemplo n.º 6
0
		Program(string[] args)
		{
			try
			{
				Common.CommandLine.Log.Write("Daves mods 1.1: " + System.Security.Principal.WindowsIdentity.GetCurrent().Name, "", Log.SeverityLevel.Message);
				Console.WriteLine("Daves mods 1.1: " + System.Security.Principal.WindowsIdentity.GetCurrent().Name);


				logLevel = (Common.CommandLine.Log.SeverityLevel)logLevelArg.Value;
				Database database = new Database(Common.Properties.ConnectionString);
				database.CreateDatabaseIfDoesNotExist();
				Console.WriteLine("CreateDatabaseIfDoesNotExist done OK");
				SqlScriptRunner.ScriptProjectRunner runner = new SqlScriptRunner.ScriptProjectRunner(
					pathToSqlProject.Directory.FullName,
					Common.Properties.ConnectionString,
					encryptScriptsInDatabase.Value,
					applyDataScripts.Value
				);
				ScriptProjectRunner.Message += new SqlScriptRunner.ScriptProjectRunner.MessageHandler(runner_Message);
				runner.SynchroniseDatabaseWithScripts();
				Console.WriteLine("SynchroniseDatabaseWithScripts done OK");
				Console.WriteLine("Finished OK");
				Environment.Exit(0);
			}
			catch (ScriptExecutionException scriptEx)
			{
				Console.WriteLine(scriptEx.ToString());
				Common.CommandLine.Log.Error(scriptEx.Message, scriptEx.ScriptFileName);
			}
			catch (CannotFindDependencyScriptException depEx)
			{
				Console.WriteLine(depEx.ToString());
				Common.CommandLine.Log.Error(depEx.Message, depEx.ExecutingScriptFileName);
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex.ToString());
				Common.CommandLine.Log.Error(ex.ToString());
			}
			Environment.Exit(1);
		}
Ejemplo n.º 7
0
		public StoredProcedure(Database database, string name)
		{
			this.database = database;
			this.name = name;
		}
Ejemplo n.º 8
0
		private static void AddStoredProcedureDefinitionsFromDatabase(Database database, CodeSections.Class storedProcedures)
		{
			foreach (StoredProcedure sp in database.StoredProcedures)
			{
				string[] storedProcedureNamespaceBreakdown = sp.Name.Split('.');
				CodeSections.Class classToPutMethodIn = storedProcedures;
				for (int i = 0; i < storedProcedureNamespaceBreakdown.Length - 1; i++)
				{
					string name = storedProcedureNamespaceBreakdown[i];
					classToPutMethodIn = GetChildClassFromFromParentClass(classToPutMethodIn, name);
				}
				string className = storedProcedureNamespaceBreakdown[storedProcedureNamespaceBreakdown.Length - 1];
				CodeSections.Class storedProcedureClass = new BobsCommonFileGenerator.CodeSections.Class(className);
				storedProcedureClass.Add(new CodeSections.StoredProcedureVoidCallMethod("ExecuteNonQuery", sp.Name, sp.Parameters));
				storedProcedureClass.Add(new CodeSections.StoredProcedureDataTableCallMethod("ExecuteDataTable", sp.Name, sp.Parameters));

				classToPutMethodIn.Add(storedProcedureClass);
			}
		}
Ejemplo n.º 9
0
		public ClassGenerator(string connectionString)
		{
			this.connectionString = connectionString;
			Dex = new DatabaseExecute(connectionString);
			database = new Database(new System.Data.SqlClient.SqlConnection(connectionString));
		}
Ejemplo n.º 10
0
		public Table(Database database, string name)
		{
			this.name = name;
			this.database = database;
			
		}
Ejemplo n.º 11
0
		internal DatabaseClrAssembly(Database databaseInfo, string assemblyName){
			this.name = assemblyName;
			this.databaseInfo = databaseInfo;
		}
		internal DatabaseExtendedProperties(Database database)
		{
			this.database = database;
		}