Reputation: 10789
Environment: .NET Framework 4.6, VS 2015, Entity Framework 6.x
I am trying to connect to a remote server but I am getting this error when I try to connect from Entity Framework:
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)
InnerException = {"The network path was not found"}
I was able to connect to the same server from the SQL Server Management Studio.
Any pointer please.
MultipleTestModel.Context.cs
public partial class fccidevEntities : DbContext
{
public fccidevEntities()
: base(hr.common.Database.EntitiesConnectionString("res://*/ef.MultipleTestModel.csdl|res://*/ef.MultipleTestModel.ssdl|res://*/ef.MultipleTestModel.msl"))
{
}
...
}
common.Database.EntitiesConnectionString :
public static string EntitiesConnectionString(string model,string)
{
try
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["fccidevConnection"].ConnectionString);
builder["MultipleActiveResultSets"] = true;
builder["Connect Timeout"] = 30;
EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();
entityBuilder.Provider = "System.Data.SqlClient";
entityBuilder.ProviderConnectionString = builder.ConnectionString;
entityBuilder.Metadata = model;
return entityBuilder.ToString();
}
catch(Exception ex)
{
throw ex;
}
}
DAL :
using (var dbTest = new fccidevEntities())
{
var EmployeeInformation = await dbTest.Employees.Where(x => x.Id == 10).FirstOrDefaultAsync();
}
web.config :
<add name="fccidevConnection"
connectionString="Data Source=System.Data.SqlClient;Initial Catalog=dev.ca.atech.com;Integrated Security=False;User Id=sa;Password=*****;MultipleActiveResultSets=True"
providerName="System.Data.SqlClient" />
Upvotes: 1
Views: 1952
Reputation: 11177
You have an error in your connection string in your config file.
This:
Data Source=System.Data.SqlClient
... is not correct. It should be something like:
Data Source=SERVER_HOST_NAME_OR_IP\SQL_SERVER_INSTANCE_NAME
Couple of examples:
Data Source=HP-14\SQLEXPRESS
Data Source=.\SQLEXPRESS
Data Source=192.168.0.19\INSTANCE14
Upvotes: 5
Reputation: 486
The server needs to be configured to handle multiple connections from the same login. or you have to manage your connections in such a way that you only ever have one connection open at any time
Upvotes: 0