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);
			}
			
        }
    	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;
    			}
    		}
    	}
Exemple #3
0
		public void RemoveAssembly(ClrAssemblyFile file)
		{
			Execute(
				String.Format(
					@"
                    IF EXISTS(SELECT TOP 1 * FROM sys.assemblies WHERE name = '{0}') BEGIN
                        DROP ASSEMBLY {0}
                    END",
					file.Name
					)
				);
		}
Exemple #4
0
		public void UpdateAssembly(ClrAssemblyFile assemblyFile){
			SetupDatabaseForClrAssemblies();
			Execute(
				String.Format(
                    @"
                    IF EXISTS(SELECT TOP 1 * FROM sys.assemblies WHERE name = '{1}') BEGIN
                        IF (UPPER(CONVERT(VARCHAR(MAX), assemblyproperty('{1}','mvid'))) <> UPPER(CONVERT(VARCHAR(MAX), '{3}'))) BEGIN
                            ALTER ASSEMBLY {1}
                            FROM '{2}'
                            WITH UNCHECKED DATA, PERMISSION_SET = UNSAFE
                        END
                    END ELSE BEGIN 
                        CREATE ASSEMBLY {1}
                        FROM '{2}'
                        WITH PERMISSION_SET = UNSAFE
                    END",
				this.DatabaseName,
				assemblyFile.Name,
				assemblyFile.FileInfo.FullName,
				assemblyFile.Mvid));
		}
 public DatabaseAssemblyLoader(SqlConnection conn, FileInfo fi, DirectoryInfo directoryToCopyAssemlyTo)
 {
     this.conn = conn;
     this.clrAssemblyFile = new ClrAssemblyFile(fi);
     this.directoryToCopyAssemlyTo = directoryToCopyAssemlyTo;
 }