Refactoring - split data, logic and model layers; custom network exception
This commit is contained in:
29
StudentHouseDashboard/Data/SqlConnectionHelper.cs
Normal file
29
StudentHouseDashboard/Data/SqlConnectionHelper.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Data
|
||||
{
|
||||
public static class SqlConnectionHelper
|
||||
{
|
||||
private static string connectionString = "Server=mssqlstud.fhict.local;Database=dbi509645;User Id=dbi509645;Password=sNPNBm*BX!6z8RM;";
|
||||
public static SqlConnection CreateConnection()
|
||||
{
|
||||
SqlConnection connection = new SqlConnection(connectionString);
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
}
|
||||
catch (SqlException e)
|
||||
{
|
||||
throw new DatabaseNetworkException("Unable to access FHICT VDI database", e);
|
||||
// Console.WriteLine("Database connection error. Are you connected to the VDI VPN?");
|
||||
}
|
||||
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user