none
UWP How to Get data from azure SQL database faster RRS feed

  • Question

  • I have use WCF and successfully acquire the data from database however there are a lot of page I need to acquire data from 2 table. Then I have solution of calling it twice by using code below

     GetTag.Service1Client client2 = new GetTag.Service1Client();
    UserList = client2.GetUserDBAsync().Result;
     GetTag.Service1Client client5 = new GetTag.Service1Client();
    PromoList = client5.GetPromotionDBAsync().Result;

    It's work and I got both User and promotion however it's very slow and I don't know the reason if it possible to make it faster

    PS. This is my code in service Both code are in the same service file but just different function

     public ObservableCollection<User> GetUserDB()
            {
                ObservableCollection<User> AllUser = new ObservableCollection<User>();
                SqlConnection conn = new SqlConnection();
                try
                {
                    conn.ConnectionString = "***";
                    conn.Open();
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = conn;
                    //Query Here
                    String cmdText = "Select * from UserDummy ";
                    cmd.CommandText = cmdText;
                    cmd.CommandType = CommandType.Text;
                    SqlDataReader dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        AllUser.Add(new User() {***});
                    }
                    dr.Close();
                    return AllUser;
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
    
                }
                throw new NotImplementedException();
            }
    public ObservableCollection<DataPromo> GetPromotionDB()
            {
                ObservableCollection<DataPromo> AllPromo = new ObservableCollection<DataPromo>();
                SqlConnection conn = new SqlConnection();
                try
                {
                    conn.ConnectionString = "***";
                    conn.Open();
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = conn;
                    //Query Here
                    String cmdText = "Select * from Promo Where PromoIsEnabled=1 AND PromoIsDeleted=0 ";
                    cmd.CommandText = cmdText;
                    cmd.CommandType = CommandType.Text;
                    SqlDataReader dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        AllPromo.Add(new DataPromo() { *** });
                    }
                    dr.Close();
    
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    if (conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
    
                }
    
                return AllPromo;
            }

     
    Wednesday, April 20, 2016 4:05 PM

Answers

  • Hi Wichaya,

    From the code snippet you providing, it seems ok, I'm not sure what cause the issue, I would suggest that you could type the sql statement and execute it in your azure sql database and check the spending time.

    In addition, you could create a static method which could log the records in a txt file (refer to the following link), then log records for some operations (such I/O operations), log the log when a operation start and finish, then check what operation spend much time.

    https://msdn.microsoft.com/en-us/library/3zc0w663(v=vs.110).aspx

    Best regards,

    Cole Wu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 21, 2016 9:55 AM
    Moderator