예제 #1
0
 /// <summary>
 /// Check if the current connection information is connected
 /// </summary>
 /// <param name="ip">Ip address</param>
 /// <param name="port">Port</param>
 /// <param name="userName">User name</param>
 /// <param name="password">Password</param>
 /// <param name="dbType">Type of DataBaseType</param>
 /// <returns>Returns true if it can connect, otherwise returns false</returns>
 public bool connect()
 {
     try
     {
         // An attempt to perform a database operation is considered incorrect if an exception is thrown
         if (DATABASE_TYPE == DataBaseType.MySql)
         {
             MySqlConnector connector = MySqlConnector.GetInstance(IP, PORT, USER_NAME, PASSWORD, "");
             DataTable      tb        = connector.ExecuteDataTable(Database.MYSQL_ALL_DATABASE_SCRIPT);
             tb.Rows[0]["Database"].ToString();
         }
         else if (DATABASE_TYPE == DataBaseType.SqlServer)
         {
             SqlServerConnector connector = SqlServerConnector.GetInstance(IP, USER_NAME, PASSWORD, "");
             DataTable          tb        = connector.ExecuteDataTable(Database.SQLSERVER_ALL_TABLE_SCRIPT);
             tb.Rows[0]["NAME"].ToString();
         }
         else if (DATABASE_TYPE == DataBaseType.Oracle)
         {
             OracleConnector connector = OracleConnector.GetInstance(IP, USER_NAME, PASSWORD);
             DataTable       tb        = connector.ExecuteDataTable(Database.ORACLE_ALL_USER_SCRIPT);
             tb.Rows[0][0].ToString();
         }
         else
         {
             // unknow database, return the false
             return(false);
         }
     }
     catch
     {
         return(false);
     }
     return(true);
 }
예제 #2
0
        /// <summary>
        /// Load all database information for this connection (oracle does not apply)
        /// </summary>
        /// <returns>List's all scheme name</returns>
        public List <string> initScheme()
        {
            List <string> schemes = new List <string>();

            try
            {
                // An attempt to perform a database operation is considered incorrect if an exception is thrown
                if (DATABASE_TYPE == DataBaseType.MySql)
                {
                    MySqlConnector connector = MySqlConnector.GetInstance(IP, PORT, USER_NAME, PASSWORD, "");
                    DataTable      tb        = connector.ExecuteDataTable(Database.MYSQL_ALL_DATABASE_SCRIPT);
                    for (int i = 0; i < tb.Rows.Count; i++)
                    {
                        schemes.Add(tb.Rows[i]["Database"].ToString());
                    }
                }
                else if (DATABASE_TYPE == DataBaseType.SqlServer)
                {
                    SqlServerConnector connector = SqlServerConnector.GetInstance(IP, USER_NAME, PASSWORD, "");
                    DataTable          tb        = connector.ExecuteDataTable(Database.SQLSERVER_ALL_TABLE_SCRIPT);
                    for (int i = 0; i < tb.Rows.Count; i++)
                    {
                        schemes.Add(tb.Rows[i]["NAME"].ToString());
                    }
                }
                else if (DATABASE_TYPE == DataBaseType.Oracle)
                {
                    OracleConnector connector = OracleConnector.GetInstance(IP, USER_NAME, PASSWORD);
                    DataTable       tb        = connector.ExecuteDataTable(Database.ORACLE_ALL_USER_SCRIPT);
                    for (int i = 0; i < tb.Rows.Count; i++)
                    {
                        schemes.Add(tb.Rows[i][0].ToString());
                    }
                }
                else
                {
                    // unknow database, return the false
                }
            }
            catch
            {
            }
            return(schemes);
        }