Skip to content

Commit

Permalink
Merge pull request #28 from devdanielsun/developer
Browse files Browse the repository at this point in the history
Update Database connection string
  • Loading branch information
devdanielsun authored Jan 10, 2024
2 parents aa97016 + f2e00bd commit 097d622
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 1 addition & 2 deletions pollor.Server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ DB_SERVER=localhost\MSSQLSERVERx
DB_NAME=name
DB_UID=
DB_PASSWORD=
DB_INTEGRATEDSECURITY=True
DB_TRUSTSERVERCERT=True
ASPNETCORE_ENVIRONMENT=Development
12 changes: 8 additions & 4 deletions pollor.Server/Services/DBConnection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dapper;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.Data.SqlClient;
using static Dapper.SqlMapper;

Expand All @@ -15,11 +16,14 @@ private DBConnection()
string dbName = Environment.GetEnvironmentVariable("DB_NAME")!;
string dbUID = Environment.GetEnvironmentVariable("DB_UID")!;
string dbPassword = Environment.GetEnvironmentVariable("DB_PASSWORD")!;
string dbIntegratedSecurity = Environment.GetEnvironmentVariable("DB_INTEGRATEDSECURITY")!;
string dbTrustServerCertificate = Environment.GetEnvironmentVariable("DB_TRUSTSERVERCERT")!;

//connectionString = string.Format("Server={0};Initial Catalog={1};Integrated Security={2};TrustServerCertificate={3}", dbServer, dbName, dbIntegratedSecurity, dbTrustServerCertificate);
connectionString = string.Format("Server={0};Database={1};UID={2};PWD={3};Integrated Security={4};TrustServerCertificate={5}", dbServer, dbName, dbUID, dbPassword, dbIntegratedSecurity, dbTrustServerCertificate);
bool isDevelopment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development";
if (isDevelopment) {
connectionString = string.Format("Server={0};Initial Catalog={1};Integrated Security={2};TrustServerCertificate={3}", dbServer, dbName, true, true);
} else { // Production
connectionString = string.Format("Server={0};Initial Catalog={1};User ID={2};Password={3};Persist Security Info={4};TrustServerCertificate={5};MultipleActiveResultSets={6};Encrypt={7};Connection Timeout={8}",
dbServer, dbName, dbUID, dbPassword, false, false, false, true, 30);
}
}

public static DBConnection Instance()
Expand Down

0 comments on commit 097d622

Please sign in to comment.