Skip to content

ConnectionString

Simon Hughes edited this page Jul 11, 2025 · 4 revisions

Using an Environment variable

Sometimes you don't have a local database and only use a cloud database and want to keep the connection string out of your code. In this case, I would recommend using an environment variable.

To edit an environment variable in Windows, click the Start button, type env, hit Enter, and click "Environment Variables" on the bottom right of the dialog.

For example, here is one I set as aa in the User variables:

image

Notice that you don't add quotes around the connection string in the environment variable.

And to pick that up in the <database>.tt file, use:

Settings.ConnectionString = Environment.GetEnvironmentVariable("aa", EnvironmentVariableTarget.User);

Clone this wiki locally