

The Environment.SetEnvironmentVariable method overload mentioned above also defaults to this behaviour, though it's probably better to be more explicit with something like: Environment.SetEnvironmentVariable("USERPROFILE", "c:\\temp", EnvironmentVariableTarget.Process) This is the behaviour when using set in the command prompt. It's worth noting that the idea here was to only change the %USERPROFILE% environment variable for the currently running process, rather than machine-wide. Probably best to do this somewhere in the entry point of the application.Īll in all this is a bit of a hack, but it at least gives one the option to store things somewhere else other than in "c:\users.".

This should be done prior to establishing a DB connection. To do this, the %USERPROFILE% environment variable must be set to the same location as above, i.e.: Environment.SetEnvironmentVariable("USERPROFILE", "c:\\temp") The next issue is actually connecting to this database from a C# application. Note that it was also necessary to create the "AppData\Local" part of the folder hierarchy manually, otherwise it fails. Msdblog.ldf system_health_0_131061520581180000.xelĪs shown, this created my LocalDB instance under c:\temp, albeit inheriting the original folder hierarchy from "AppData" onward (which seems unchangeable). 286.Ĭ:\Users\dan.smith>cd C:\temp\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\testĬ:\temp\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\test>dir /wĭirectory of C:\temp\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\test LocalDB instance "test" created with version. The following worked for me (using SQLLocalDB from a command prompt): C:\Users\dan.smith>echo %USERPROFILE%Ĭ:\Users\dan.smith>set USERPROFILE=c:\tempĬ:\Users\dan.smith>mkdir c:\temp\AppData\LocalĬ:\Users\dan.smith>sqllocaldb create test After some experimentation, it seems that the SQLLocabDB command line utility uses the %USERPROFILE% environment variable (rather than %LOCALAPPDATA%) to find this location. As alluded to in previous posts, it appears that it defaults to %LOCALAPPDATA%\Microsoft\Microsoft SQL Server Local DB\Instances. I've also been trying to customise the instances location, and have found a solution.
