Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello,
Im getting following error and im new to MVC

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)

1.I have tried to enable TCP/IP in sql server manager,port number is not available in
server congif manager...kepet default sql port number
2. Also tried to connect using wirewall connection in control.
3.web.config everything is correct and also routeconfig is also correct.



Nothing worked..could any one help me to solve the problem ..and please do post connection string ...i have tried everything


Thank you
Posted
Comments
CHill60 14-Jan-15 6:27am    
Can you post your connection string and the code you are using to connect please
_Asif_ 14-Jan-15 7:15am    
Do a telnet HOST_IP 1521 and check whether it is getting connected or not

Search for services in control panel, there you will find and entry View Local Services in Admin tool section

select it that will show a window with all services in your system, find your service SQLEXPRESS and click on Start. It should start your server instance :)
 
Share this answer
 
Comments
Member 11148509 14-Jan-15 5:04am    
ya have done it showing status as started.... but no change could not get the connection
kedar001 14-Jan-15 5:14am    
please check...
1.) http://blog.sqlauthority.com/2009/05/21/sql-server-fix-error-provider-named-pipes-provider-error-40-could-not-open-a-connection-to-sql-server-microsoft-sql-server-error/

2.) http://www.technologycrowds.com/2014/02/could-not-open-connection-to-sql-server.html
Member 11148509 14-Jan-15 5:33am    
Thank u i have already tried those ...
Your "Server" on that connectionString does not look correct to me ... are you trying to connect to a local SQLExpress instance? In which case it should be "Server=.\SQLExpress;"

See https://www.connectionstrings.com/sql-server/[^] for other variations
 
Share this answer
 
Comments
Member 11148509 14-Jan-15 7:46am    
i have used my pc/instance name userid password also but dint not get
Finally got it :-) :-)

1.Check the connection string ...if u dint not get..
2.Goto-> all programs->micrsoft sql server 2008 ->configuration tools->sql server configuration manager-> go tu ur isntance and anable tcp/ip and ryt click on tcp/ip and set port number.
3.control panel ->admin tools -> services->check wetaher sql is started.


all ur suggestions worked out

Thank you
 
Share this answer
 
Please check the SQL Server instance is running or not.

1. Type services.msc in RUN
2. Find SQL Server (MSSQLServer) and Right click, choose 'Start'
 
Share this answer
 
Comments
Member 11148509 14-Jan-15 6:26am    
already i have done that im unable to understand whats the error ..i have tried each and everything ..before posting here
CHill60 14-Jan-15 6:26am    
OP stated that he has already checked that ... an hour ago
Member 11148509 14-Jan-15 6:33am    
namespace BusinessLayer
{
public class EmployeeBusinessLayer
{
public IEnumerable Employees
{
get
{
string connectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
List employees = new List();
using (SqlConnection con = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand("AllEmployees", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Employee employee = new Employee();
employee.EmployeeID = Convert.ToInt32(dr["EmployeeID"]);
employee.Name = dr["Name"].ToString();
employee.Gender = dr["Gender"].ToString();
employees.Add(employee);

}
}
return employees;

}
}
}

connection string :
<connectionstrings>
<add name="DBCS"
="" connectionstring="Server=.;Database=project; Integrated Security=SSPI;" providername="System.Data.SqlClient">

Member 11148509 14-Jan-15 6:35am    
connectionString="Server=.;Database=databasename; Integrated Security=SSPI;"


this is the connection string i have also changed this using uderid password and data source
Sathiyamoorthy Natarajan 14-Jan-15 7:45am    
As per understanding from your Connection String, you are connecting to your local machine.

But it seems you have not configured for local machine while installing SQL Server. It has been installed to connect with network only.

Please check the below link for your reference.

http://www.pinaldave.com/bimg/2008small/200814.jpg

http://www.pinaldave.com/bimg/2008small/200815.jpg

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900