| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- using System;
- using Npgsql;
- namespace RestaurantApp.DAL
- {
- public static class Database
- {
- private const string Host = "edu-pg.itiscaf.ru";
- private const int Port = 5432;
- private const string DbName = "dbwork";
- private const string User = "shagavaliev_iv";
- private const string Password = "75&n057$380";
- private const string Schema = "shagavaliev_iv";
- public static string ConnectionString =>
- $"Host={Host};Port={Port};Database={DbName};Username={User};Password={Password};Search Path={Schema};";
- public static NpgsqlConnection GetConnection()
- {
- var conn = new NpgsqlConnection(ConnectionString);
- conn.Open();
- return conn;
- }
- public static bool TestConnection(out string error)
- {
- error = "";
- try
- {
- using (var conn = GetConnection()) { }
- return true;
- }
- catch (Exception ex)
- {
- error = ex.Message;
- return false;
- }
- }
- }
- }
|