Hello Experts, Hope You Are Doing Well.
I am Trying To Create a WebApi. However My Approach Is Little Different Because Of My Manager Ask Me To Do Like That.
My Whole Project Is In .Net Core FrameWork 6.
1. Main WebAPI
2. Services (Different Project Same FrameWork)
3. Models (Different Project Same FrameWork)
Below Code Is No 2. DB Connecion Service Project.
The Whole Api Is Interlinked. And References Is Added. However. WebApi Is Running Fine. But When I Try To Login To Get The Token.
Error Comes "system.platformnotsupportedexception 'system.data.sqlclient is not supported on this platform.'
Could Anyone Please Help.
using Core.Mbm.Hrm.Model;
using System.Data;
using System.Data.SqlClient;
namespace Core.Mbm.Hrm.Services
{
public class HrLogin
{
public static class GetConString
{
public static string ConString()
{
var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
var config = builder.Build();
string constring = config.GetConnectionString("DbConn");
return constring;
}
}
public string CheckUserPassword(LoginModel obj)
{
//using (SqlConnection dbconn = new SqlConnection(DbConn.ConnectionString))
using (SqlConnection dbconn = new SqlConnection(GetConString.ConString()))
{
SqlCommand COM = new SqlCommand("WP_USER_LOGIN_CHECK", dbconn);
COM.CommandType = CommandType.StoredProcedure;
SqlDataReader RD;
try
{
COM.Parameters.AddWithValue("@EMPNO", obj.UserId);
COM.Parameters.AddWithValue("@PASSWORD", obj.Password);
if (dbconn.State == System.Data.ConnectionState.Closed)
{
dbconn.Open();
}
RD = COM.ExecuteReader();
if (RD.HasRows)
{
RD.Read();
Int16 _VALID = 0;
_VALID = Int16.Parse(RD["VL"].ToString());
if (_VALID == 1) //&& obj.HostDetails == RD["REG_HOSTID"].ToString())
{
return "1";
}
else
{
return "0";
}
}
}
catch (SqlException ex)
{
throw;
}
finally
{
COM.Dispose();
dbconn.Close();
}
}
return "0";
}
}
}