Location of temporary files

jbsoundjbsound Posts: 35
edited August 15, 2006 1:24PM in SQL Toolkit Previous Versions
Is there a way to specify where the temporary files are created?

I looked at the TempFile class, but it doesn't seem to contain a property or method to set the path for the temporary files.

As discussed in a different thread, we have the issue of a large database seemingly requiring a large amount of temporary space in order to do a transfer. So the thought was to rewrite the application to store the temporary files on a drive that had sufficient free space.

Any suggestions?

JB

Comments

  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    Hello,

    It can't be set in the API, but if you add an environment variable to the application called RGTEMP, the application will use the location specified in the environment variable.
    using System;
    using System.Runtime.InteropServices;
    using System.Security;
    using System.Security.Permissions;
    namespace SQLCompareCodeSnippets
    {
         class Class1
        {
    // Import the Kernel32 dll file.
    [DllImport("kernel32.dll",CharSet=CharSet.Auto, SetLastError=true)]
    
    [return:MarshalAs(UnmanagedType.Bool)]
    
    // The declaration is similar to the SDK function
    public static extern bool SetEnvironmentVariable(string lpName, string lpValue);
    [STAThread]
    static void Main( )
    {
    SetEnvironmentVariableEx("RGTEMP", @"c:\temp");
    
    }
    
    public static bool SetEnvironmentVariableEx(string environmentVariable, string variableValue)
    {
    	try
    	{
    		// Get the write permission to set the environment variable.
    		EnvironmentPermission environmentPermission = new EnvironmentPermission(EnvironmentPermissionAccess.Write,environmentVariable);
    
    		environmentPermission.Demand(); 
    
    		return SetEnvironmentVariable(environmentVariable, variableValue);
    	}
    	catch( SecurityException e)
    	{
    		Console.WriteLine("Exception:" + e.Message);
    	}
    	return false;
    }
    }
    }
    
Sign In or Register to comment.