Skip to content

ConnectionString

Simon Hughes edited this page Oct 12, 2022 · 2 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:

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);