-
Notifications
You must be signed in to change notification settings - Fork 226
ConnectionString
Simon Hughes edited this page Jul 11, 2025
·
7 revisions
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:

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);- Home
- Compared with the Microsoft scaffolder
- Connection strings
- JetBrains Rider
- Upgrading from v3 to v4
- Saving .tt does nothing
- Settings A-Z - every setting, with a page each
- Common Settings Types Explained
- Settings Callbacks
- Settings runtime values and helpers
- Filtering
- Full Control Over the Generated Code
- Enum Generation from Table Data
- Owned Entities
- JSON column support
- Global Query Filters
- Extended Property Names Feature
- Partial Properties
- File-Scoped Namespaces
- Data Annotations
- Spatial Types
- HierarchyId
- RowVersion and TimeStamp columns
- Lazy Loading
- Stored proc result sets