4

I keep getting this error:

Format of the initialization string does not conform to specification starting at index 165.

and I can't seem to find the problem .

connection code :

 <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\LarandeModulDB.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />

    <add name="LarandeModulDBEntities" connectionString="metadata=res://*/Models.EntityModel.LMDBModel.csdl|res://*/Models.EntityModel.LMDBModel.ssdl|res://*/Models.EntityModel.LMDBModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDB)\v11.0;attachdbfilename=&quot;|DataDirectory|\LarandeModulDB.mdf&quot;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

  </connectionStrings>

The code that I use to retrieve an employee with the same ID which has the same as the Id of the person that is logged in:

var employeeId = context.SchoolEmployee.FirstOrDefault(r => r.UserId.Equals(userId)); 

That code returns:

An exception of type 'System.ArgumentException' occurred in EntityFramework.dll but was not handled in user code
Additional information: Format of the initialization string does not conform to specification starting at index 165.

public List<Employee> GetClassInfo1( string userId)
{
    using (var context = new LarandeModulDBEntities())
    {
        var list = new List<Employee>();

            var employeeId = context.SchoolEmployee.FirstOrDefault(r => r.UserId.Equals(userId));
            var c = context.Class.Where(r => r.TeacherId.Equals(employeeId.Id)).ToList();
            foreach (var i in c)
            {
                var e = new Employee();
                e.Grade = i.Grade;
                e.Id = i.Id;
                e.Name = i.Name;
                e.TeacherId = i.TeacherId;
                list.Add(e);
            }
        return list;
    }
}

1 Answer 1

4

You probably copied/pasted the connection string together. There are too many &quot; symbols:

connection string=&quot;data source=(LocalDB)\v11.0;attachdbfilename=&quot;|DataDirectory|\LarandeModulDB.mdf&quot;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;

should be

connection string=&quot;data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\LarandeModulDB.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;

Sign up to request clarification or add additional context in comments.

1 Comment

I had a &quot; at the end of my password and missed the additional ; which was needed when I added MARS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.