0

i keep getting this error and tried to delete the data source but that gave me another error and also tried to add another connection string also did not work how can i fix this? https://ibb.co/4sVbnZt

 DbsCarEntities1 dbs = new DbsCarEntities1();
    string maincon = ConfigurationManager.ConnectionStrings["DbsCarEntities1"].ConnectionString;

   public ActionResult Admin1()
    {
        return View();
    }
    [HttpPost]
    public ActionResult Admin1(Admin x)
    {
        string maincon = ConfigurationManager.ConnectionStrings["DbsCarEntities1"].ConnectionString;
        SqlConnection sqlcon = new SqlConnection(maincon);
        string sqlquery = "select UserName,Password from [dbo].[Admin] where UserName=@UserName and Password=@Password";
        sqlcon.Open();
        SqlCommand sqlcom = new SqlCommand(sqlquery, sqlcon);
        sqlcom.Parameters.AddWithValue("@UserName", x.UserName);
        sqlcom.Parameters.AddWithValue("@Password", x.Password);
        SqlDataReader sdr = sqlcom.ExecuteReader();
        if (sdr.Read())
        {
            Session["UserName"] = x.UserName.ToString();
            return RedirectToAction("Main2");
        }
        else
        {
            ViewData["Message"] = "Admin Login Details Does NOT match our data records!";
        }

        sqlcon.Close();
        return View();
    }
    
    public ActionResult Main2()
    {

        return View(dbs.Cars.ToList());
    }
sOmeDevv
  • 11
  • 3

1 Answers1

0

You have to change the provider name to System.Data.SqlClient from System.Data.EntityClient in your connection.I think it will resolve your issue.

<add name="DbsCarEntities1" 
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;
AttachDbFilename=C:\Users\hamza\source\repos\CarSaleProjectUsingMVCandDataBase\CarSaleProjectUsingMVCandDataBase\App_Data\DbsCar.mdf;Integrated Security=True;" providerName="System.Data.SqlClient" />

Pritom Sarkar
  • 2,154
  • 3
  • 11
  • 26