I am facing an issue with my Android app, which used to work fine when communicating with the server, but after the server's IP address changed, I'm now experiencing slow response times from the server. Here's a bit more detail:
Before the IP change, everything worked perfectly, and response times were fast.
After the IP change, the app takes much longer to receive a response from the server. Sometimes it works faster, but there are periods when it is quite slow.
In my local environment, the app works faster and the responses are as expected.
I have already taken several steps to improve the performance, such as:
Changing API responses to return JSON instead of other formats.
Moving long database queries into stored procedures to optimize execution time.
Adding indexes to the database to improve query performance.
Despite these efforts, the issue persists.
The app was working fine before the IP change, so I'm wondering if this is related to the IP change in some way. Here’s the server-side code I’m using to handle the request. The method fetches pending fees from the database using a stored procedure:
[HttpGet]
public async Task<IHttpActionResult> get_pending_fees(string admno)
{
// Use a `using` statement for automatic resource cleanup
using (SqlConnection c1 = new SqlConnection(cong))
{
List<get_hos_relive> rt = new List<get_hos_relive>();
try
{
// SQL query to call the stored procedure
string query = "GetPendingFees"; // Name of stored procedure
// Open the connection asynchronously
await c1.OpenAsync();
using (SqlCommand cmd = new SqlCommand(query, c1))
{
cmd.CommandType = CommandType.StoredProcedure; // Set the command type to Stored Procedure
// Add parameter to avoid SQL injection
cmd.Parameters.AddWithValue("@admno", admno);
// Use SqlDataReader to read data
using (SqlDataReader dr = await cmd.ExecuteReaderAsync())
{
while (await dr.ReadAsync())
{
var it = new get_hos_relive
{
coll = Convert.ToString(dr["Collection"]),
dem = Convert.ToString(dr["Demand"]),
sch = Convert.ToString(dr["Scholar"]),
bal = Convert.ToString(dr["Balance"])
};
rt.Add(it);
}
}
}
return Json(rt);
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
return Json(rt); // Return the partially filled list if there's an error
}
}
}