Question

I am getting error "The underlying provider failed on Open." actually i haven't call entity frame work connection string my code is,

 InspectionEntities dbContext = new InspectionEntities();

how to pass entity fram work connection string when "InspectionEntities" is as ,

namespace DataAccessManager
{
    public class InspectionEntities : ObjectContext
    {
        public InspectionEntities();
        public InspectionEntities(EntityConnection connection);
        public InspectionEntities(string connectionString);

and inspection is as,

[assembly: EdmSchemaAttribute()]

namespace DataAccessManager
{
    #region Contexts

    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    public partial class InspectionEntities : ObjectContext
    {
        #region Constructors

        /// <summary>
        /// Initializes a new InspectionEntities object using the connection string found in the 'InspectionEntities' section of the application configuration file.
        /// </summary>
        public InspectionEntities() : base("name=InspectionEntities", "InspectionEntities")
        {
            OnContextCreated();
        }

        /// <summary>
        /// Initialize a new InspectionEntities object.
        /// </summary>
        public InspectionEntities(string connectionString) : base(connectionString, "InspectionEntities")
        {
            OnContextCreated();
        }

        /// <summary>
        /// Initialize a new InspectionEntities object.
        /// </summary>
        public InspectionEntities(EntityConnection connection) : base(connection, "InspectionEntities")
        {
            OnContextCreated();
        }

        #endregion

and my connection string is,

<add name="InspectionEntities" connectionString="metadata=res://*/Inspection.csdl|res://*/Inspection.ssdl|res://*/Inspection.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=*****\SQLEXPRESS;Initial Catalog=Inspection;User ID=sa;Password=****;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

InspectionEntities dbContext = new InspectionEntities();

when i use its object dbcontext in getting data it give me error for underlying provider failed on open

How to pass or call entity connection string in here,

InspectionEntities dbContext = new InspectionEntities("name=InspectionEntities"); ????

i am getting same here

Hopes for your suggestion

Thanks in Advance

Was it helpful?

Solution

You don't have to pass the connection string to your context constructor. Instead change it in the web.config file.

The error you are receiving points that the SQL server name or instance name is specified incorrectly or there is a firewall blocking the connection. If it would be username/password issue you would get an error saying that login is not possible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top