Good morning friends I am seeing some tutorials on the management of asynchronous programming with .net, in windows form .. many show concepts and basic practices on how to implement it.
But my doubts is. when we want to work with persistence of data, either with Databases. Would I have to make an asynchronous connection?
I'm looking at the documentation with a micro orm called dapper. and reviewing some of their methods, some have implemented that part by default.
for example. This is the way to work synchronously
var result = VariablesGlobales.GlobalConnection.Query("SELECT * FROM ...").firstOrDefault();
It turns out that there is another similar function but adding Async in their method to differentiate them.
var result = await VariablesGlobales.GlobalConnection.QueryAsync("SELECT * FROM ...");
My connection could be said to be a global statement of this. in a static class.
public static class VariablesGlobales
{
private static System.Data.SqlClient.SqlConnection _GlobalConnection;
public static String UsuarioNombre { get; set; }
public static String EmpresaNombre { get; set; }
public static String SucursalNombre { get; set; }
public static int UsuarioID { get; set; }
public static int EmpresaID { get; set; }
public static int SucursalID { get; set; }
public static int RolID { get; set; }
public static string Rol { get; set; }
// TIEMPO DE EJECUCION DE LA APLICACION, Y BLOQUEO EN TIEMPO DE INACTIVIDAD
public static int Horas { get; set; }
public static int Minutos { get; set; }
public static System.Data.SqlClient.SqlConnection GlobalConnection
{
get
{
_GlobalConnection = _GlobalConnection ?? new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
return _GlobalConnection;
}
set
{
_GlobalConnection = value;
}
}
}
Now working with the ExecuteAsync .. and performing the basic operations in a Database.
Is an asynchronous connection necessary? If so, how can you implement it?
Thank you.