Wrox Programmer Forums
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 1st, 2006, 08:47 PM
Authorized User
Join Date: May 2006
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default connection error with SQL

Hello All,
I am working in vwd using C#. In my web develpent I am Connecting to the Sql server 2000's pubs table and displaying result in GridView Control.
My Coding is

SqlConnection con = new SqlConnection("Server=local host;uid=sa;pwd=kumar;database=pubs");
        string str = "select * from authors";
        SqlDataAdapter da = new SqlDataAdapter(str, con);
        DataSet ds = new DataSet();
        GridView1.DataSource = ds;

This is a very simple Code.
Now I got a error which is

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)

Can you tell me what is the problem here

rajkumar sharma
rajkumar sharma
Old June 2nd, 2006, 01:52 PM
Authorized User
Join Date: May 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts

Try to add this line

Old June 2nd, 2006, 02:50 PM
Registered User
Join Date: Jun 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts

are you still getting error..? Let me know I will be able to help you.

Old June 5th, 2006, 08:56 PM
Authorized User
Join Date: Apr 2005
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts

I am taking a shot at the dark but I don't see a server instance with your connection string. I see the localhost but I do believe every sql servr has an instance name. It should look something like localhost\instance name...or machinename\instance name.
To get the instance you can just see what your sql manager connects to that you used to build your database and use that.

Old June 5th, 2006, 11:30 PM
Authorized User
Join Date: May 2006
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts

Hello ALL,
thnx for your replies.The Problem is solved and the answer is

In my Connection string "server=localhost" is correct and i was writing
Server=local host.

1. there should me no space between local and host
2. S should be in small case in word Server

rajkumar sharma

Similar Threads
Thread Thread Starter Forum Replies Last Post
sql connection error navbingo20 ASP.NET 2.0 Basics 0 June 23rd, 2008 05:07 PM
Chapter 16 Sql connection error flashmanTom BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 1 May 22nd, 2008 05:04 PM
connection error with SQL sh.rajkumar ASP.NET 2.0 Professional 0 June 1st, 2006 08:48 PM
SQL server connection error Mayuri25 Pro VB Databases 4 September 12th, 2005 05:42 AM
SQL Server Connection error shivani_desai SQL Server 2000 1 January 16th, 2005 03:53 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.