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.

For example, here is one I set as aa in the User variables: Start, type env, hit enter, click "Environment Variables" on the bottom right of the dialog. The following screen will appear:

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