Пример #1
0
        public List <Poco.DataBase> GetDatabases()
        {
            var lstDataBases = new List <Poco.DataBase>();

            try
            {
                var query = $"SELECT database_id, name FROM sys.databases";

                var dt = MssqlHelper.ExecuteQuery(query);
                foreach (DataRow dr in dt.Rows)
                {
                    var db = new Poco.DataBase();
                    db.Id   = int.Parse(dr["database_id"].ToString());
                    db.Name = dr["name"].ToString();

                    lstDataBases.Add(db);
                }

                return(lstDataBases);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        public List <Poco.Table> GetTables(Poco.DataBase database)
        {
            var lstTables = new List <Poco.Table>();

            try
            {
                this.Database = database.Name;

                if (isAuth)
                {
                    MssqlHelper.DefaultConnectionString = $"Server={server};Database={Database};Trusted_Connection=True;";
                }
                else
                {
                    MssqlHelper.DefaultConnectionString = $"Server={server};Database={Database};User Id={username};Password={password};";
                }

                var query = $"SELECT object_id, name FROM sys.Tables ORDER BY name";

                var dt = MssqlHelper.ExecuteQuery(query);
                foreach (DataRow dr in dt.Rows)
                {
                    var tb = new Poco.Table();
                    tb.Id       = int.Parse(dr["object_id"].ToString());
                    tb.Name     = dr["name"].ToString();
                    tb.DataBase = database;

                    lstTables.Add(tb);
                }

                return(lstTables);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }