mirror of
https://github.com/stokebob/BealeEngineering.git
synced 2026-03-19 06:37:15 +00:00
Added database connection check at application startup
This commit is contained in:
@@ -26,6 +26,15 @@ namespace BealeEngineering.Accounts
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
sqlConnectionString = ConfigurationManager.ConnectionStrings["BealeEngSQLDb"].ToString();
|
sqlConnectionString = ConfigurationManager.ConnectionStrings["BealeEngSQLDb"].ToString();
|
||||||
|
|
||||||
|
// test for sql connection
|
||||||
|
string dbConnMessage = new Core.Data.Database.Connection(sqlConnectionString).IsServerConnected();
|
||||||
|
if (dbConnMessage != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show(dbConnMessage, "Database connection error", MessageBoxButtons.OK);
|
||||||
|
Environment.Exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
assignInvoice = new Core.Logic.Sale.AssignInvoice(sqlConnectionString);
|
assignInvoice = new Core.Logic.Sale.AssignInvoice(sqlConnectionString);
|
||||||
UpdateInvoiceImportText();
|
UpdateInvoiceImportText();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,5 +22,21 @@ namespace BealeEngineering.Core.Data.Database
|
|||||||
|
|
||||||
this.sqlConnectionString = sqlConnectionString;
|
this.sqlConnectionString = sqlConnectionString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string IsServerConnected()
|
||||||
|
{
|
||||||
|
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
catch (SqlException ex)
|
||||||
|
{
|
||||||
|
return ex.InnerException;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user