Open a MessageBox and provide a message if a connection fails. This handles incorrected values for the server name, the database name, or anything else (including security) which would cause a connection to fail.
This commit is contained in:
parent
4540344b0b
commit
b39fc7a048
@ -260,9 +260,9 @@ namespace VEPROMS.CSLA.Library
|
|||||||
{
|
{
|
||||||
string strConn = VEPROMS_Connection; // If failure - Fail (Don't try to catch)
|
string strConn = VEPROMS_Connection; // If failure - Fail (Don't try to catch)
|
||||||
// Attempt to make a connection
|
// Attempt to make a connection
|
||||||
|
SqlConnection cn = new SqlConnection(strConn);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SqlConnection cn = new SqlConnection(strConn);
|
|
||||||
cn.Open();
|
cn.Open();
|
||||||
return cn;
|
return cn;
|
||||||
}
|
}
|
||||||
@ -289,6 +289,8 @@ namespace VEPROMS.CSLA.Library
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Open a MesageBox so the user is given some feedback that the connection has failed.
|
||||||
|
ReportInnermostException(exsql,strConn);
|
||||||
throw new ApplicationException("Failure on Connect", exsql);
|
throw new ApplicationException("Failure on Connect", exsql);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -299,6 +301,20 @@ namespace VEPROMS.CSLA.Library
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Open a MessageBox with the exception type, the connection string and the exception message
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ex">exception being processed</param>
|
||||||
|
/// <param name="conn">connection string</param>
|
||||||
|
private static void ReportInnermostException(Exception ex, string conn)
|
||||||
|
{
|
||||||
|
// walk up the exception stack to find the innermost exception.
|
||||||
|
while (ex.InnerException != null)
|
||||||
|
ex = ex.InnerException;
|
||||||
|
System.Windows.Forms.MessageBox.Show(string.Format("{0}\r\n\r\nConnection String ={1}", ex.Message,conn)
|
||||||
|
,"PROMS - " + ex.GetType().FullName, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
|
||||||
|
System.Diagnostics.Process.GetCurrentProcess().Kill();
|
||||||
|
}
|
||||||
public static void PurgeData()
|
public static void PurgeData()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
Loading…
x
Reference in New Issue
Block a user