1

I have a Database named SalesERPDB and I'm trying to create a new table "TblEmployee", but getting an exception on creating the same.

public class SalesERPDB : DbContext
{
    public SalesERPDB() : base("SalesERPDB")
    {

    }

    public DbSet<Employee> Employees { get; set; }
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Employee>().ToTable("TblEmployee");
        base.OnModelCreating(modelBuilder);
    }
}

EmployeeBusinessLayer class (Where i have a method GetEmployees() to get the employee list):

public class EmployeeBusinessLayer
{
    public List<Employee> GetEmployees()
    {
        SalesERPDB salesDal = new SalesERPDB();
        return salesDal.Employees.ToList(); // Getting an exception in this line.
    }
}

Employee Class:

public class Employee
{
    [Key]
    public int EmployeeId { get; set; }
    public string FName { get; set; }
    public string LName { get; set; }
    public int Salary { get; set; }
}

I'm able to hit the same connection string from a different application.

Connection string:

<connectionStrings>
<add name="SalesERPDB" connectionString="Data Source=CSCINDAI406933\\SQLEXPRESS;Initial Catalog=SalesERPDB;Integrated Security=True;" providerName="System.Data.SQLClient"></add>

Exception details:

Description: An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code

Exception Details: System.InvalidOperationException: Instance failure. Stack trace: [InvalidOperationException: Instance failure.] System.Web.Mvc.Async.<>c__DisplayClass46.b__3f() +323 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +78 System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +191 System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) +119 System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +44 System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +47 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +136 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +50 System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +72 System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) +154 System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) +21 System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry) +141 System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry) +362 System.Data.SqlClient.SqlConnection.Open() +96 System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<Open>b__36(DbConnection t, DbConnectionInterceptionContext c) +12 System.Data.Entity.Infrastructure.Interception.InternalDispatcher1.Dispatch(TTarget target, Action2 operation, TInterceptionContext interceptionContext, Action3 executing, Action3 executed) +72 System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext) +405 System.Data.Entity.SqlServer.<>c__DisplayClass33.<UsingConnection>b__32() +459 System.Data.Entity.SqlServer.<>c__DisplayClass1.<Execute>b__0() +15 System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func1 operation) +190 System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation) +82 System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action1 act) +194 System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action1 act) +427 System.Data.Entity.SqlServer.SqlProviderServices.CheckDatabaseExists(SqlConnection sqlConnection, Nullable1 commandTimeout, String databaseName) +86 System.Data.Entity.SqlServer.SqlProviderServices.DbDatabaseExists(DbConnection connection, Nullable1 commandTimeout, Lazy1 storeItemCollection) +347 System.Data.Entity.Core.Common.DbProviderServices.DatabaseExists(DbConnection connection, Nullable1 commandTimeout, Lazy1 storeItemCollection) +122 System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185 System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +42 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +133 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40 System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +70 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +133 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44 System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +62 System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +133 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39 System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39 System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +39 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +70 System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +37 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9644037 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

Fix for this issue would be really appreciated. Thanks in advance.

2
  • update ur question with connection string Commented Nov 19, 2016 at 12:38
  • @MidhunMundayadan Updated the question with connectionString Commented Nov 19, 2016 at 17:49

1 Answer 1

2

As you got the error "instance failure" based on stack trace , that might be the error with your SQL Server instance. change data source like Data Source=.\SQLEXPRESS

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

1 Comment

Yes, The issue was with my Server instance, updated Data Source value to \SQLEXPRESS from \\SQLEXPRESS. It worked.

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.