Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot connect to local SQL Server

Status
Not open for further replies.

iaswnidou

Programmer
Apr 19, 2005
140
GR
Hello

I am using Visual Studio 2008 and SQL Server 2005.

I have a solution that includes an Office Excel 2007 Workbook project and a class library. When I run the Excel form comes up and I am trying to retrieve data from my local SQL Server on clicking a button.

The code I use is
[using (SqlCommand comm = conn.CreateCommand())
{
comm.CommandText = "SELECT * FROM Soldiers";

conn.Open();

SqlDataReader reader = comm.ExecuteReader(CommandBehavior.CloseConnection);]

When I open the connection though an exception is thrown. Look below:

[An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]

I have configured the SQL Instance to allow remote connections through the Management Studio and also used the Surface Area Configuration to fix the problem. Still though I receive the error.

I remember this was happening at my work and we could not work for a whole day as we couldn't find a solution. The next day the problem would fix itself. I never had this happening locally though. Have you got any idea why?
 
Thanks a lot, I connected to the database using the Server Explorer and picked up the connection string from there.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top