1. my json file
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ConnectionStrings": {
"Database": "Data Source=;Initial Catalog=BookingService;TrustServerCertificate=True;User ID=sa; Password=PFCLP@08122022;Integrated Security=false;"
},
"AllowedHosts": "*"
}
2. Database Connection Method
public static SqlConnection GetDbCon()
{
try
{
SqlConnection con = new SqlConnection();
con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStrings"].ConnectionString;
return con;
}
catch (Exception ex)
{
throw ex;
}
}
3. Data Access Method
public static List
{
using (SqlConnection SqlCn = DBMasterCon.GetDbCon())
{
SqlCommand cmd = new SqlCommand("SPVM_BookingReferenceTblPARA", SqlCn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@BookingRefNo", SqlDbType.VarChar, 50).Value = BookingRefNo;
SqlCn.Open();
List
try
{
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
BookingReferenceTbl grdcsd = new BookingReferenceTbl();
grdcsd.BookingRefNo = (string)Convert.ToString(reader["BookingRefNo"]);
grdcsd.ReturnOption = (string)System.Convert.ToString(reader["ReturnOption"]);
grdcsd.OneWayOption = (string)System.Convert.ToString(reader["OneWayOption"]);
grdcsd.MultiCityOption = (String)System.Convert.ToString(reader["MultiCityOption"]);
grdcsd.TravelFrom = (string)Convert.ToString(reader["TravelFrom"]);
grdcsd.TravelTo = (string)System.Convert.ToString(reader["TravelTo"]);
grdcsd.DepartTime = (DateTime)System.Convert.ToDateTime(reader["DepartTime"]);
grdcsd.ReturnDate = (DateTime)Convert.ToDateTime(reader["ReturnDate"]);
grdcsd.CabinClassTravelers = (string)System.Convert.ToString(reader["CabinClassTravelers"]);
csd.Add(grdcsd);
}
reader.Close();
return csd;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
SqlCn.Close();
}
}
}
No i got the error on this implementation please help to resolve on this error

Vishal YelvePosted Apr 4, 2023, 11:02 AM
Hi Rolando,
You need to import
and In your controller
Or In Startup.cs file inside ConfigureServices method
do refer below link
https://www.yogihosting.com/ado-net-aspnet-core/
https://www.c-sharpcorner.com/article/database-operations-in-asp-net-core-web-api-using-ado-net2/
https://www.c-sharpcorner.com/article/crud-operations-in-asp-net-core-web-api-using-ado-net/
https://www.youtube.com/watch?v=0o26oTUutuw
https://www.connectionstrings.com/store-and-read-connection-string-in-appsettings-json/
Rolando PunoPosted Apr 4, 2023, 7:26 AM
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Admin.Data.Access
StackTrace:
at Admin.Data.Access.DBMasterCon.GetDbCon() in C:\FiCSC\MICROSERVICE\HRMS\Services\AdminServiceApps\Admin.Data.Access\DBMasterCon.cs:line 49
Hello this the error when i debug 2. Database Connection Method

Rajeesh MenothPosted Apr 2, 2023, 3:33 AM
Hi,
Explain the error details then only we can provide the right solution.