/* * for check the connections * no return type * */ static private void CheckConnections() { Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("\n-----------------Check Connections--------------------\n"); Console.ForegroundColor = ConsoleColor.DarkGreen; //check Mongo Db MongoDBConnector mongoCon = new MongoDBConnector(); Console.WriteLine("....MongoDB....\n"); StatusWriter(mongoCon.CheckDB()); Console.WriteLine("\n------------------------------------------------------\n"); //check Postger Db PostgrSqlDbConnector postgerCon = new PostgrSqlDbConnector(); Console.WriteLine("....PostgerDB....\n"); StatusWriter(postgerCon.CheckDB()); Console.WriteLine("\n------------------------------------------------------\n"); //check Mysql Db MySqlDBConnector mysqlCon = new MySqlDBConnector(); Console.WriteLine("....MysqlDB....\n"); StatusWriter(mysqlCon.CheckDB()); Console.WriteLine("\n------------------------------------------------------\n"); //check Mssql Db MsSqlDBConnector mssqlCon = new MsSqlDBConnector(); Console.WriteLine("....Mssql....\n"); StatusWriter(mssqlCon.CheckDB()); Console.WriteLine("\n------------------------------------------------------\n"); }
public void Read(string tabalName) { Console.WriteLine("Connecting....."); MsSqlDBConnector getCon = new MsSqlDBConnector(); SqlConnection con = getCon.GetCon(); try { con.Open(); Console.WriteLine("Connected\n"); string sql = "select * FROM " + tabalName; SqlCommand cmd = new SqlCommand(sql, con); SqlDataReader red = cmd.ExecuteReader(); DataSet set = new DataSet(); while (red.Read()) { for (int i = 0; i < red.FieldCount; i++) { Console.WriteLine(red[i].ToString()); } Console.WriteLine("\n----------------------------------\n"); } } catch (SqlException e) { Console.WriteLine("\tError: " + e.Number.ToString() + "\n\t has occurred: " + e.Message.ToString()); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } finally { if (con.State == System.Data.ConnectionState.Open) { con.Close(); } } }
public List <string> GetTables() { MsSqlDBConnector dbCon = new MsSqlDBConnector(); SqlConnection con = dbCon.GetCon(); try { con.Open(); string sql = "USE " + ConfigurationManager.AppSettings["initialCatalog"] + " SELECT * FROM INFORMATION_SCHEMA.TABLES"; SqlCommand cmd = new SqlCommand(sql, con); SqlDataReader red = cmd.ExecuteReader(); List <string> tableNames = new List <string>(); while (red.Read()) { tableNames.Add(red["TABLE_NAME"].ToString()); } return(tableNames); } catch (Exception) { throw; } }
public List <string> ReadRelations(string tbName) { MsSqlDBConnector dbCon = new MsSqlDBConnector(); SqlConnection con = dbCon.GetCon(); try { con.Open(); string sql = "EXEC sp_fkeys '" + tbName + "'"; SqlCommand cmd = new SqlCommand(sql, con); List <string> joinTables = new List <string>(); SqlDataReader red = cmd.ExecuteReader(); joinTables.Add(tbName); while (red.Read()) { joinTables.Add(red["FKTABLE_NAME"].ToString()); } return(joinTables); } catch (Exception) { throw; } }