Wasted
Wasted
CC#
Created by Wasted on 11/15/2024 in #help
✅ Random error only when app is run on same server as database
I made a simple dotnet application that uses a remote database When I run it on my local computer it works flawlessly, I dont see the error and the application works When I run it on the same server as the database half of the time I get errors half the time it works correctly with no error I was told the connection needs to be closed but I dont think I did that correctly as I still get the same errors The errors I get are This method may not be called when another read operation is pending. or Connection must be valid and open. or Object reference not set to an instance of an object. This is most common, the save does appear to work as the database gets updated but the app shows this error This is the database class
namespace DataLibrary
{
public class DataAccess : IDataAccess
{
public async Task<List<T>> LoadData<T, U>(string sql, U parameters, string connectionString)
{
using (IDbConnection connect = new MySqlConnection(connectionString))
{
var rows = await connect.QueryAsync<T>(sql, parameters);
connect.Close();
return rows.ToList();
}
}
public Task SaveData<T>(string sql, T parameters, string connectionString)
{
using (IDbConnection connect = new MySqlConnection(connectionString))
{
var value = connect.ExecuteAsync(sql, parameters);
connect.Close();
return value;

}
}
}
}
namespace DataLibrary
{
public class DataAccess : IDataAccess
{
public async Task<List<T>> LoadData<T, U>(string sql, U parameters, string connectionString)
{
using (IDbConnection connect = new MySqlConnection(connectionString))
{
var rows = await connect.QueryAsync<T>(sql, parameters);
connect.Close();
return rows.ToList();
}
}
public Task SaveData<T>(string sql, T parameters, string connectionString)
{
using (IDbConnection connect = new MySqlConnection(connectionString))
{
var value = connect.ExecuteAsync(sql, parameters);
connect.Close();
return value;

}
}
}
}
22 replies