From 1b649ea00dde1e9744f501912253bda17c2dc565 Mon Sep 17 00:00:00 2001 From: Saranga Athukorale Date: Mon, 25 Jan 2016 12:46:45 +0530 Subject: [PATCH] A Fix for the Previous Commit Signed-off-by: Saranga Athukorale --- .../classes/sqlce/ConnectionManager.cs | 57 +++++++------------ 1 file changed, 22 insertions(+), 35 deletions(-) diff --git a/libDatabaseHelper/classes/sqlce/ConnectionManager.cs b/libDatabaseHelper/classes/sqlce/ConnectionManager.cs index fdca032..562fabd 100644 --- a/libDatabaseHelper/classes/sqlce/ConnectionManager.cs +++ b/libDatabaseHelper/classes/sqlce/ConnectionManager.cs @@ -63,11 +63,21 @@ public override bool CheckConnectionString(string connectionString) } catch {} + var connectionCretead = CreateConnection(null, connectionString); + if (connectionCretead != null && connectionCretead.State == System.Data.ConnectionState.Open) + { + return true; + } + return false; + } + + protected override DbConnection CreateConnection(Type t, string connectionString) + { + SqlCeConnection connection = null; try { - var connection = new SqlCeConnection(connectionString); + connection = new SqlCeConnection(connectionString); connection.Open(); - connection.Close(); } catch (System.Data.SqlServerCe.SqlCeInvalidDatabaseFormatException) { @@ -75,44 +85,21 @@ public override bool CheckConnectionString(string connectionString) { var engine = new SqlCeEngine(connectionString); engine.Upgrade(); - } - catch (System.Exception ex) - { - Console.WriteLine("Attempt on Upgrading SQL CE Database Failed (Reason = \"" + ex.Message + "\")"); - return false; - } - try - { - var connection = new SqlCeConnection(connectionString); - connection.Open(); - connection.Close(); + try + { + connection = new SqlCeConnection(connectionString); + connection.Open(); + } + catch (System.Exception){} } - catch (System.Exception) + catch (System.Exception ex) { - return false; + Console.WriteLine("Attempt on Upgrading SQL CE Database Failed (Reason = \"" + ex.Message + "\")"); } } - catch (Exception) - { - return false; - } - return true; - } - - protected override DbConnection CreateConnection(Type t, string connectionString) - { - try - { - var connectionCreated = new SqlCeConnection(connectionString); - connectionCreated.Open(); - return connectionCreated; - } - catch (Exception ex) - { - Console.WriteLine("Unable to connect with conenction string = \"" + connectionString + "\" due to : " + ex.Message); - return null;/*(frmConnectionStringSetter.ShowWindow(t, GetSupportedDatabaseType()) ? GetConnection() : null)*/ ; - } + catch (Exception) {} + return connection; } public void LoadConnectionData()