Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 1st, 2006, 08:47 PM
Authorized User
 
Join Date: May 2006
Location: New Delhi, Delhi, India.
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();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();


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
http://www.apnasaathi.blogspot.com
Reply With Quote
  #2 (permalink)  
Old June 2nd, 2006, 01:52 PM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try to add this line
con.Open();

Reply With Quote
  #3 (permalink)  
Old June 2nd, 2006, 02:50 PM
Registered User
 
Join Date: Jun 2005
Location: , New York, USA.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #4 (permalink)  
Old June 5th, 2006, 08:56 PM
Authorized User
Points: 333, Level: 6
Points: 333, Level: 6 Points: 333, Level: 6 Points: 333, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Fresno, California, USA.
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
  #5 (permalink)  
Old June 5th, 2006, 11:30 PM
Authorized User
 
Join Date: May 2006
Location: New Delhi, Delhi, India.
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

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

rajkumar sharma
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:07 PM.


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