{"id":22065866,"url":"https://github.com/karenpayneoregon/appsettings-basics","last_synced_at":"2026-05-09T15:32:01.375Z","repository":{"id":110840268,"uuid":"393322949","full_name":"karenpayneoregon/appsettings-basics","owner":"karenpayneoregon","description":"Working with appsetting.json, see branch AccessSqEntity","archived":false,"fork":false,"pushed_at":"2022-12-27T15:03:32.000Z","size":1168,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T18:17:37.655Z","etag":null,"topics":["appsettings","chsarp"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/karenpayneoregon.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-06T09:13:14.000Z","updated_at":"2024-06-11T18:39:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"59ac065c-a203-48a0-94e4-20de3f8a1160","html_url":"https://github.com/karenpayneoregon/appsettings-basics","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/karenpayneoregon/appsettings-basics","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karenpayneoregon%2Fappsettings-basics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karenpayneoregon%2Fappsettings-basics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karenpayneoregon%2Fappsettings-basics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karenpayneoregon%2Fappsettings-basics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/karenpayneoregon","download_url":"https://codeload.github.com/karenpayneoregon/appsettings-basics/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karenpayneoregon%2Fappsettings-basics/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32824326,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-08T08:22:46.396Z","status":"online","status_checked_at":"2026-05-09T02:00:06.633Z","response_time":123,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["appsettings","chsarp"],"created_at":"2024-11-30T19:22:20.532Z","updated_at":"2026-05-09T15:32:01.355Z","avatar_url":"https://github.com/karenpayneoregon.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Appsetting connection library for .NET Core projects\n\nProvides samples for using appsettings.json for .NET Core/C# 9 instead of using app.config\n\n- Currently there is only one example for working with SQL-Server, later other examples will following.\n- Proper usage is to keep, in this case SqlServerConnectionLibrary project in this solution, when needed for your solution reference this project's DLL\n\n## Addendum\n\nThe only difference between `Oracle` and `SQL-Server` is the actual `connection string`. The methods used are the same for telling Oracle how to connect to your database.\n\n![assets/oracle1.png](./assets/oracle1.png)\n\nFor SQL-Server we have three environments\n\n```json\n{\n  \"ConnectionStrings\": {\n    \"DevelopmentConnection\": \"Data Source=.\\\\SQLEXPRESS;Initial Catalog=NorthWind2020;Integrated Security=True\",\n    \"ProductionConnection\": \"Data Source=ProductionServer;Initial Catalog=NorthWind2020;Integrated Security=True\",\n    \"TestConnection\": \"Data Source=TestServer;Initial Catalog=NorthWind2020;Integrated Security=True\",\n    \"Environment\": 2\n  }\n}\n```\n\nTo get the default connection, in this case `Development`\n\n```csharp\npublic static bool ConnectionTest()\n{\n    Helper.Initializer();\n    \n    using var cn = new SqlConnection() { ConnectionString = Helper.ConnectionString };\n\n    try\n    {\n        cn.Open();\n        return true;\n    }\n    catch (Exception)\n    {\n        return false;\n    }\n}\n```\n\nHow are environments known\n\n```csharp\npublic enum Environments\n{\n    Production,\n    Test,\n    Development\n}\n```\n\nAn enum is used rather than a string as a string can be mistyped and cause a runtime error.\n\nNote that Helper.Initializer(); need only be called once in an application, not for each call.\n\nExample\n\n```csharp\nusing System.Data.SqlClient;\nusing SqlServerConnectionLibrary;\n\nnamespace AppSettingsCoreUnitTestProject.Classes\n{\n    public class SqlOperations\n    {\n        public static string ConnectionString = \"\";\n\n        public static CustomerRelation GetCustomers()\n        {\n\n            InitializeConnection();\n            \n            CustomerRelation customer = new();\n\n            var selectStatement = \"TODO\";\n\n            using var cn = new SqlConnection() { ConnectionString = ConnectionString };\n            using var cmd = new SqlCommand() { Connection = cn, CommandText = selectStatement };\n\n            cn.Open();\n\n            var reader = cmd.ExecuteReader();\n\n            if (reader.HasRows)\n            {\n                reader.Read();\n                customer.CustomerIdentifier = reader.GetInt32(0);\n                customer.CompanyName = reader.GetString(1);\n                customer.City = reader.GetString(2);\n                customer.PostalCode = reader.GetString(3);\n                customer.ContactId = reader.GetInt32(4);\n                customer.CountryIdentifier = reader.GetInt32(5);\n                customer.Country = reader.GetString(6);\n                customer.Phone = reader.GetString(7);\n                customer.PhoneTypeIdentifier = reader.GetInt32(8);\n                customer.ContactPhoneNumber = reader.GetString(9);\n                customer.ModifiedDate = reader.GetDateTime(10);\n                customer.FirstName = reader.GetString(11);\n                customer.LastName = reader.GetString(12);\n            }\n\n            return customer;\n\n        }\n\n        private static void InitializeConnection()\n        {\n            if (!string.IsNullOrWhiteSpace(ConnectionString)) return;\n            Helper.Initializer();\n            ConnectionString = Helper.ConnectionString;\n        }\n    }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarenpayneoregon%2Fappsettings-basics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkarenpayneoregon%2Fappsettings-basics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarenpayneoregon%2Fappsettings-basics/lists"}