public void run() { Exception exp = null; IDbConnection ICon = new OleDbConnection(); try { BeginCase("check IDbConnection is null"); Compare(ICon != null, true); } catch(Exception ex){exp = ex;} finally{EndCase(exp); exp = null;} try { BeginCase("check IDbConnection type"); Compare(ICon.GetType().FullName ,typeof(OleDbConnection).FullName); } catch(Exception ex){exp = ex;} finally{EndCase(exp); exp = null;} ICon = new OleDbConnection(_ConnectionString); try { BeginCase("check IDbConnection connection string"); Compare(ICon.ConnectionString ,_ConnectionString); } catch(Exception ex){exp = ex;} finally{EndCase(exp); exp = null;} try { BeginCase("check IDbConnection ConnectionTimeout"); Compare(ICon.ConnectionTimeout ,15); } catch(Exception ex){exp = ex;} finally{EndCase(exp); exp = null;} try { BeginCase("check IDbConnection state - closed"); Compare(ICon.State ,ConnectionState.Closed); } catch(Exception ex){exp = ex;} finally{EndCase(exp); exp = null;} ICon.Open(); try { BeginCase("check IDbConnection - open"); Compare(ICon.State ,ConnectionState.Open ); } catch(Exception ex){exp = ex;} finally{EndCase(exp); exp = null;} try { BeginCase("check IDbConnection CreateCommand"); IDbCommand cmd = ICon.CreateCommand(); Compare(cmd.GetType().FullName ,typeof(OleDbCommand).FullName); } catch(Exception ex){exp = ex;} finally{EndCase(exp); exp = null;} if (ICon.State == ConnectionState.Open) ICon.Close(); }
/// <summary> /// /// </summary> /// <param name="connectionName">Name of connection (should be held in sources connections collection) to be opened /// and placed in openConnections if not already there. (If it is already there then nothing is done)</param> /// <returns></returns> private void openConnection(RRConnectionString connection) { if (openConnections.ContainsKey(connection.Name)) // Have already opened that connection, do nothing return; else { var connString = buildConnectionString(connection.Name); try { /* // Have not yet opened that connection, so open it and save to collection if (connection.DatabaseType == DatabaseType.Teradata) { var openConnection = new TdConnection(connString); openConnection.Open(); openConnections.Add(connection.Name, openConnection); } else { */ var openConnection = new OleDbConnection(connString); openConnection.Open(); var connType = openConnection.GetType(); openConnections.Add(connection.Name, openConnection); } catch (Exception ex) { throw new ApplicationException(string.Format("Error trying to open connection with {0}: {1}.", connString, getFullErrorMessage(ex))); } } }