only open connection if it's closed.
This commit is contained in:
@@ -76,7 +76,10 @@ namespace CarCareTracker.Controllers
|
||||
try
|
||||
{
|
||||
var pgDataSource = new NpgsqlConnection(_configHelper.GetServerPostgresConnection());
|
||||
pgDataSource.Open();
|
||||
if (pgDataSource.State == System.Data.ConnectionState.Closed)
|
||||
{
|
||||
pgDataSource.Open();
|
||||
}
|
||||
InitializeTables(pgDataSource);
|
||||
//pull records
|
||||
var vehicles = new List<Vehicle>();
|
||||
@@ -421,7 +424,10 @@ namespace CarCareTracker.Controllers
|
||||
try
|
||||
{
|
||||
var pgDataSource = new NpgsqlConnection(_configHelper.GetServerPostgresConnection());
|
||||
pgDataSource.Open();
|
||||
if (pgDataSource.State == System.Data.ConnectionState.Closed)
|
||||
{
|
||||
pgDataSource.Open();
|
||||
}
|
||||
InitializeTables(pgDataSource);
|
||||
//pull records
|
||||
var vehicles = new List<Vehicle>();
|
||||
|
||||
@@ -16,7 +16,10 @@ namespace CarCareTracker.External.Implementations
|
||||
_logger = logger;
|
||||
try
|
||||
{
|
||||
pgDataSource.Open();
|
||||
if (pgDataSource.State == System.Data.ConnectionState.Closed)
|
||||
{
|
||||
pgDataSource.Open();
|
||||
}
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
|
||||
@@ -16,7 +16,10 @@ namespace CarCareTracker.External.Implementations
|
||||
_logger = logger;
|
||||
try
|
||||
{
|
||||
pgDataSource.Open();
|
||||
if (pgDataSource.State == System.Data.ConnectionState.Closed)
|
||||
{
|
||||
pgDataSource.Open();
|
||||
}
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
|
||||
@@ -16,7 +16,10 @@ namespace CarCareTracker.External.Implementations
|
||||
_logger = logger;
|
||||
try
|
||||
{
|
||||
pgDataSource.Open();
|
||||
if (pgDataSource.State == System.Data.ConnectionState.Closed)
|
||||
{
|
||||
pgDataSource.Open();
|
||||
}
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
|
||||
@@ -16,7 +16,10 @@ namespace CarCareTracker.External.Implementations
|
||||
_logger = logger;
|
||||
try
|
||||
{
|
||||
pgDataSource.Open();
|
||||
if (pgDataSource.State == System.Data.ConnectionState.Closed)
|
||||
{
|
||||
pgDataSource.Open();
|
||||
}
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
|
||||
@@ -16,7 +16,10 @@ namespace CarCareTracker.External.Implementations
|
||||
_logger = logger;
|
||||
try
|
||||
{
|
||||
pgDataSource.Open();
|
||||
if (pgDataSource.State == System.Data.ConnectionState.Closed)
|
||||
{
|
||||
pgDataSource.Open();
|
||||
}
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
|
||||
@@ -16,7 +16,10 @@ namespace CarCareTracker.External.Implementations
|
||||
_logger = logger;
|
||||
try
|
||||
{
|
||||
pgDataSource.Open();
|
||||
if (pgDataSource.State == System.Data.ConnectionState.Closed)
|
||||
{
|
||||
pgDataSource.Open();
|
||||
}
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
|
||||
@@ -16,7 +16,10 @@ namespace CarCareTracker.External.Implementations
|
||||
_logger = logger;
|
||||
try
|
||||
{
|
||||
pgDataSource.Open();
|
||||
if (pgDataSource.State == System.Data.ConnectionState.Closed)
|
||||
{
|
||||
pgDataSource.Open();
|
||||
}
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
|
||||
@@ -16,7 +16,10 @@ namespace CarCareTracker.External.Implementations
|
||||
_logger = logger;
|
||||
try
|
||||
{
|
||||
pgDataSource.Open();
|
||||
if (pgDataSource.State == System.Data.ConnectionState.Closed)
|
||||
{
|
||||
pgDataSource.Open();
|
||||
}
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
|
||||
@@ -16,7 +16,10 @@ namespace CarCareTracker.External.Implementations
|
||||
_logger = logger;
|
||||
try
|
||||
{
|
||||
pgDataSource.Open();
|
||||
if (pgDataSource.State == System.Data.ConnectionState.Closed)
|
||||
{
|
||||
pgDataSource.Open();
|
||||
}
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
|
||||
@@ -16,7 +16,10 @@ namespace CarCareTracker.External.Implementations
|
||||
_logger = logger;
|
||||
try
|
||||
{
|
||||
pgDataSource.Open();
|
||||
if (pgDataSource.State == System.Data.ConnectionState.Closed)
|
||||
{
|
||||
pgDataSource.Open();
|
||||
}
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
|
||||
@@ -15,7 +15,10 @@ namespace CarCareTracker.External.Implementations
|
||||
_logger = logger;
|
||||
try
|
||||
{
|
||||
pgDataSource.Open();
|
||||
if (pgDataSource.State == System.Data.ConnectionState.Closed)
|
||||
{
|
||||
pgDataSource.Open();
|
||||
}
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, body TEXT not null, emailaddress TEXT not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
|
||||
@@ -16,7 +16,10 @@ namespace CarCareTracker.External.Implementations
|
||||
_logger = logger;
|
||||
try
|
||||
{
|
||||
pgDataSource.Open();
|
||||
if (pgDataSource.State == System.Data.ConnectionState.Closed)
|
||||
{
|
||||
pgDataSource.Open();
|
||||
}
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
|
||||
@@ -16,7 +16,10 @@ namespace CarCareTracker.External.Implementations
|
||||
_logger = logger;
|
||||
try
|
||||
{
|
||||
pgDataSource.Open();
|
||||
if (pgDataSource.State == System.Data.ConnectionState.Closed)
|
||||
{
|
||||
pgDataSource.Open();
|
||||
}
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (userId INT, vehicleId INT, PRIMARY KEY(userId, vehicleId))";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
|
||||
@@ -16,7 +16,10 @@ namespace CarCareTracker.External.Implementations
|
||||
_logger = logger;
|
||||
try
|
||||
{
|
||||
pgDataSource.Open();
|
||||
if (pgDataSource.State == System.Data.ConnectionState.Closed)
|
||||
{
|
||||
pgDataSource.Open();
|
||||
}
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT primary key, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
|
||||
@@ -15,7 +15,10 @@ namespace CarCareTracker.External.Implementations
|
||||
_logger = logger;
|
||||
try
|
||||
{
|
||||
pgDataSource.Open();
|
||||
if (pgDataSource.State == System.Data.ConnectionState.Closed)
|
||||
{
|
||||
pgDataSource.Open();
|
||||
}
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, username TEXT not null, emailaddress TEXT not null, password TEXT not null, isadmin BOOLEAN)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
|
||||
@@ -16,7 +16,10 @@ namespace CarCareTracker.External.Implementations
|
||||
_logger = logger;
|
||||
try
|
||||
{
|
||||
pgDataSource.Open();
|
||||
if (pgDataSource.State == System.Data.ConnectionState.Closed)
|
||||
{
|
||||
pgDataSource.Open();
|
||||
}
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
|
||||
Reference in New Issue
Block a user