Filip Karlsson
Filip Karlsson

Reputation: 65

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

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;
    }
}

Upvotes: 4

Views: 9130

Answers (1)

Gert Arnold
Gert Arnold

Reputation: 109080

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;

Upvotes: 5

Related Questions