Search code examples
asp.netasp.net-mvc-4membership-providerrole-manager

MemberShip Create Role


Additional information:

An error occurred while attempting to initialize a System.Data.SqlClient.SqlConnection object. The value that was provided for the connection string may be wrong, or it may contain an invalid syntax.

I'm creation new role in my web application. When i add new role i got an error i don't have any idea about it kindly help me.

Connection string :

<connectionStrings>
    <add name="PayRollContext" connectionString="metadata=res://*/PayRollDataModel.csdl|res://*/PayRollDataModel.ssdl|res://*/PayRollDataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=ATI_SHAH\SQLEXPRESS;initial catalog=PayRollManagmentSystem;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

Controller where i get an error here: {var chkRole = Roles.RoleExists(rolename);}

public ActionResult CreatRole(aspnet_Roles role)
{
    string rolename = role.RoleName;
    if (ModelState.IsValid)
    {
        var chkRole = Roles.RoleExists(rolename);
        if (chkRole == true)
        {
            ModelState.AddModelError("Name", "* Role Already Exist");
        }
        else
        {
            Roles.CreateRole(rolename);
            return RedirectToAction("ListRole", "Role");
        }
    }
    return View();
}

Solution

  • The rest of the data in there (the metadata, etc.) is just confusing SQL Server.

    <add name="PayRollContext" connectionString="data source=ATI_SHAH\SQLEXPRESS;initial catalog=PayRollManagmentSystem;multipleactiveresultsets=True;integrated security=True;App=EntityFramework">