Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
4.06/5 (3 votes)
See more:
Hi all I am doing one Asp.Net MVC Application. I am very new to this in that I am getting the following Exception

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

Can anybody please help me .Thanks in advance


This is my code inside Controller:-
----------------------------------------
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcAppDataAccess.Models;

namespace MvcAppDataAccess.Controllers
{
    public class EmployeeController : Controller
    {
        //
        // GET: /Employee/

        public ActionResult Details(int Id)
        {
            EmployeeContext empobj = new EmployeeContext();
          Employee obj =  empobj.Employees.Single(emp => emp.EmpId == Id);// This is the line of Error.
            return View(obj);
        }

    }
}

This Goes inside Model
---------------------------
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations.Schema;


namespace MvcAppDataAccess.Models
{
   [Table("Employee")]
    public class Employee
    {
        public int EmpId { get; set; }
        public string EmpName { get; set; }
        public string EmpJob { get; set; }
        public double EmpSal { get; set; }
        public int DeptId { get; set; }
    }
}

this is my Context Class
---------------------------
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;


namespace MvcAppDataAccess.Models
{
    public class EmployeeContext:DbContext
    {
        public DbSet<Employee> Employees { get; set; }
    }
}


this one is the details view
------------------------------
HTML
@model MvcAppDataAccess.Models.Employee

@{
    ViewBag.Title = "Employee Details";
}

<h2>Employee Details</h2>
<table>
<tr>
<td>
Employee ID:-
</td>
<td>
@Model.EmpId
</td>
</tr>
<tr>
<td>
Employee Name:-
</td>
<td>
@Model.EmpName
</td>
</tr>
<tr>
<td>
Employee Job:-
</td>
<td>
@Model.EmpJob
</td>
</tr>
<tr>
<td>
Employee Salary
</td>
<td>
@Model.EmpSal
</td>
</tr>
<tr>
<td>
Department ID:-
</td>
<td>
@Model.DeptId
</td>
</tr>
</table>



Below is the Content of Web.Config File
---------------------------------------

XML
<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
  <connectionStrings>
    <add name="EmployeeContext" connectionString="Server:MAVENSOFT\SQLEXPRESS; id:workflow;password:workflow;Database:Sample" providerName="System.Data.SqlClient" />
  </connectionStrings>//this block of code for ConnectionString
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>
Posted
Updated 12-May-14 18:53pm
v7
Comments
[no name] 12-May-14 10:14am    
You would need to fix the format of the string.
CHill60 12-May-14 10:15am    
We can't see your screen so you will have to post the code giving you the problem here. Use the Improve question link
BillWoodruff 12-May-14 16:30pm    
It's a good idea to show the code where the error occurs.
Mukesh Pr@sad 13-May-14 0:34am    
can you please check the error

It's a problem of wrong connectionstring. Please check your web.config file see the connectionstring is correct or not.
 
Share this answer
 
Comments
Sanket Saxena 13-May-14 1:02am    
Correct +5
[no name] 13-May-14 1:07am    
thanks :)
Sanket Saxena 13-May-14 1:27am    
most welcome :)
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900