I'm briefly new into Blazor. I was wondering if it's possible to make a very basic connection to mysql database server hosted remotely via simple function:
string connectionString = "data source = database ip here,1600;Initial Catalog=HDSERVER;Persist Security Info=True; User ID=user_id; Password=Password()";
int idUser = -1;
UserModel User = new UserModel();
public class UserModel
{
public string name { get; set; }
public string pin { get; set; }
}
private void LoginUser()
{
Console.WriteLine(User.name);
Console.WriteLine(User.pin);
{
try
{
Console.WriteLine("starting sql connection...");
SqlConnection c = new SqlConnection(connectionString);
Console.WriteLine("opening..");
c.Open();
Console.WriteLine("sql connection open..");
SqlCommand cmd = new SqlCommand("Login", c);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@pin", pinCode);
Console.WriteLine("getting data");
var pId = cmd.Parameters.AddWithValue("@idUser", idUser);
Console.WriteLine("pId: ", pId);
pId.Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
c.Close();
Console.WriteLine("sql connection closed..");
int id = (int)pId.Value;
Console.WriteLine("id: ", id);
if (id > 0)
{
NavigationManager.NavigateTo("/home");
}
else
{
Console.WriteLine("Cannot sing in!");
}
}
catch (Exception e)
{
Console.WriteLine("Error: ");
Console.WriteLine(e.Message);
}
}
}
Or maybe there is another specific way for doing that? I usually typing code in js & react, so for me everything here is so new and a little confusing me. It would be great as well if someone could share any tips how to do such things or from where getting a knowledge about Blazor !
Thanks in advance!