0

I write web page in MVC, which use Entity Framework as ORM mapper. I put my connection string to web.config file. Here is it:

<add name="JP_CMS" connectionString="Data Source=.;Initial Catalog=JP_CMS;
User Id=CmsWebUser;Password=abcd1234abcd1234;"
providerName="System.Data.SqlClient"/>

I try to get data by this C# code

    public DataBaseContext()
        : base("JP_CMS")
    {
        Database.SetInitializer(new DropCreateDatabaseIfModelChanges<DataBaseContext>());
    }

//------------------------------

    var db = new DataBaseContext();
    var result = db.Articles.ToList(); //<- here is thrown exception
//------------------------------

My local SQL server is running, this table is exists, but I get excepion like in this:

enter image description here

I think it is the most important expection: "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"

Could you help my by give some idea what I make wrong?

6
  • The exception image is not helpful. Please mention the valid exception. Did you derive DataBaseContext class from ObjectContext class? It doesnt look so. Commented Aug 16, 2013 at 8:29
  • Are you trying to connect to a specific instance? Commented Aug 16, 2013 at 8:30
  • I try to get my own local SQL Server Commented Aug 16, 2013 at 8:33
  • Which version of SQL Server? also, are you using Data Source=. in the connection string? Commented Aug 16, 2013 at 8:37
  • Have you tried connecting to this server (. means local server) using SSMS from the machine where the code is running? Does it give the same error? Commented Aug 16, 2013 at 8:40

3 Answers 3

2

"The system cannot find the file specified" error. Check carefully your connection string.

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

3 Comments

I think taht problem is in my connection string, but I have no idea where. It's possibe that EF have problem when db must be recreated and I specify login and password do access db?
Can you write your SQL server version?
Specify data source like this Data Source=.\SQLExpress Also check, is your server is turn on, is the user name and a password are correct, is data base with name "JP_CMS" exists on yours SQL Server instance. And check is user "CmsWebUser" has permission to work with data base "JP_CMS"
1

hi Error indicates EF tried to connect to the server but failed.

Could you Checkk,

1) SQL Server should be up and running.

Go to All Programs >> Microsoft SQL Server 2008 >> Configuration Tools >> SQL Server Configuration Manager >> SQL Server Services, and check if SQL Server service status is “Running”.

In addition, ensure that your remote server is in the same network. Run “sqlcmd -L” in your command prompt to ascertain if your server is included in your network list.

2) Enable TCP/IP in SQL Server Configuration

For more info you can go here

Comments

1

Instead of DataSource =. try DataSource = .\sqlInstanceName. Also DataSource=(local) might work.

Comments

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.