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:-
----------------------------------------
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
{
public ActionResult Details(int Id)
{
EmployeeContext empobj = new EmployeeContext();
Employee obj = empobj.Employees.Single(emp => emp.EmpId == Id);
return View(obj);
}
}
}
This Goes inside Model
---------------------------
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
---------------------------
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
------------------------------
@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
---------------------------------------
="1.0"="utf-8"
<configuration>
<configSections>
<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>