Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;
    }
}
like image 201
Filip Karlsson Avatar asked Oct 28 '25 15:10

Filip Karlsson


1 Answers

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;

like image 157
Gert Arnold Avatar answered Oct 31 '25 07:10

Gert Arnold



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!