Question

How do I connect to SQL08 through asp.net?

Asked by: jay-are

Hello Experts:

I'm having trouble using one of my everyday .net programs to connect to our new sql08 server.  I have a sql2k and a sql2k5 server that never give me grief with this program.  Whenever I try to connect to one of the databases I get the following error:

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)

I've tried it using my normal connectionstring that works in 2k and 2k5.  I tried it with the IP of the sql server, then I tried using the named instance of the server or what I THINK is the named instance...

I've tried odd combos of "myserver\instance" and all the rest.  I tried using the standard connectionstrings from:  http://www.connectionstrings.com/sql-server-2008 as well.  Still the same error.  My router has a firewall rule to allow port 1432-1434 through to my server.  The sql server is also our webserver so I'm sure there is some permissions issue that I'm not able to find.  The program I'm testing is a vb.net web app.  Here is the sub for db connect:

Sub Button1_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim ConnectionString As String = "workstation id=""me"";packet size=4096;user id=user1;password=password;data source=""DA-SQL03\SQL03"";persist security info=False;initial catalog=customers"
            'sql08 connectionstring from link above - Dim ConnectionString As String = "Server=DA-SQL03\SQL03;Database=customers;User ID=user1;Password=password;Trusted_Connection=False;"
            Dim conn As New SqlConnection(ConnectionString)
            Dim query As String = "SELECT * FROM login WHERE username = @username AND password = @password AND clientid = @clientid"
            Dim newcommand As New SqlCommand(query, conn)
            newcommand.Connection = conn
            conn.Open()

                                  
1:
2:
3:
4:
5:
6:
7:
8:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-05-22 at 12:43:54ID24432230
Topics

SQL Server 2008

,

Programming for ASP.NET

,

Microsoft Visual Basic.Net

Participating Experts
2
Points
500
Comments
31

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. ASP.NET label grief
    Hi, I am programming in asp.net and am using C# as the language. I am trying to write to a label on the Page_Load event by getting some text from an array of Strings and then using the Label.Text method to set the text of the label. However, I find that if the text is lon...
  2. The programming languages used for the everyday applicati…
    I have been very interested to know for quite a while now, what programming languages are used to code our everyday applications, and whether it is benefitial to learn them. For example; Microsoft Office 2003. Antivirus software. Firewall software. And other third party pr...
  3. "Incorrect syntax near 'GO'" in asp.net application sq…
    Hi all, I have a question, the below sql server script i have running on an asp.net site connected to a sqlserver2k errors out with the following error: "System.Data.SqlClient.SqlException: Line 10: Incorrect syntax near 'GO'." As a solo programmer from home that ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: mfreudenPosted on 2009-05-22 at 13:12:41ID: 24454710

What version of SQL 08 are you using?  

If it's 2008 express, you need to allow for remote access:

http://blogs.msdn.com/sqlexpress/archive/2005/05/05/415084.aspx

 

by: jay-arePosted on 2009-05-22 at 13:24:40ID: 24454809

I don't believe I have express.  I don't see Express anywhere, also in the config manager I don't see a section for sql express.  TCP/IP is enabled though.  Windows firewall is off.  

 

by: RiteshShahPosted on 2009-05-22 at 18:21:58ID: 24456290

can you please run following query and give us the exact result coming from it?



--To get the product version, use :
SELECT SERVERPROPERTY('productversion') as ProductVersion
 
 
--To get the Service Pack information or the level of version, use :
SELECT SERVERPROPERTY ('productlevel') as Level
 
 
--To get the product edition, use :
SELECT SERVERPROPERTY('edition') as EDITION

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:

Select allOpen in new window

 

by: jay-arePosted on 2009-05-22 at 21:11:32ID: 24456672

Product Version:  10.0.1600.22

Level:  RTM

Edition:  Standard Edition (64-bit)

 

by: RiteshShahPosted on 2009-05-22 at 21:15:05ID: 24456677

well Jay-are, now it is confirmed that you are not using express but standard so there might be quite a few reason which can show you this error, my friend and SQL Server MVP has recently written one article which covers almost all possibility of this error. have a look.

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/

Ritesh Shah
www.SQLHub.com

 

by: jay-arePosted on 2009-05-23 at 12:07:28ID: 24459172

Ok I completed all the steps in that article.  I didn't have an alias to begin with but I added one anyway.  Not sure about that last step.

I rebooted after doing everything just to make certain.  I still get the same error.  I think that perhaps my connection string is just wrong.  This is the first sql server I've had that had a named instance...Typically I just connect to my other servers using the IP for the server name.  So I'm not certain I'm using the right string.  Here is the original:

Dim ConnectionString As String = "workstation id=""me"";packet size=4096;user id=user1;password=password;data source=""DA-SQL03\SQL03"";persist security info=False;initial catalog=customers"

and the one I tried from the site listed above:
Dim ConnectionString As String = "Server=DA-SQL03\SQL03;Database=customers;User ID=user1;Password=password;Trusted_Connection=False;"

The server name inside the console shows: DA-SQL03\SQL03

The user is setup is called user1.  I've tried different variations of the server name and none seem to get me past that error.  Any other ideas?

 

by: jay-arePosted on 2009-05-23 at 14:16:00ID: 24459539

I really think it is a problem with the connection string I'm using.  I changed to this:

Dim ConnectionString As String = "Server=""DA-SQL03\Sql03"";Database=Customers;User ID=DA-SQL03\administrator;Password=password;Trusted_Connection=True;"

and now I get the following error:

Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.
Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.

Throws this exception when I try to open the connection in my vb.net program.

 

by: mfreudenPosted on 2009-05-23 at 14:36:10ID: 24459607

When you use Truseted Connection=True, the UserI d and Password are ignored and the system attempts to log you in as the Current ActiveDir user.  If this is a scheduled job, then it will use the ActiveDir user the job runs under,

Based on your errors, it sounds like the SQL server was installed in "Windows Authentication" mode only and NOT in "SQL Server and Windows Authentication" mode.  Therefore you'll have to use Trusted Connection=True.

3 qusetions:

1. Is the PC you're running the VB code in the same domain as the SQL server?

2. Can you access the SQL server with your activedir logon from SQL Server management console on your PC?

3. if so, are you running the VB code with same login?

 

by: jay-arePosted on 2009-05-23 at 17:54:54ID: 24460077

Ah ok, I thought I was onto something with that Trusted Connection.

When I run the code from the actual server or my remote devbox I get the same error.  The server isn't part of a domain and isn't using Active Directory unless WS2k8 installs this by default, I certainly didn't choose it.  I assume my vb.net programs run using the asp.net user?

 

by: mfreudenPosted on 2009-05-23 at 20:17:32ID: 24460345

Try and get the SQL serve switched to:  "SQL Server and Windows Authentication" mode.

This can be done by right-clicking the server name within the SQL management console, then select the security tab, and change the option from "windows authentication" to   "SQL Server and Windows Authentication".  This is how your other servers are probably configured anyway.

Once this is done and there is a valud SQL logon for you to use, you're 1st connection string at the begining of this thread should work fine.

 

by: jay-arePosted on 2009-05-23 at 22:01:21ID: 24460517

Yeah that was something I changed right away.  So it has been in sql/windows auth mode the whole time.  The other servers are setup this way which is why I'm so confused about this problem.

 

by: jay-arePosted on 2009-05-24 at 11:04:40ID: 24462383

I changed my code back to my original connection string using the proper named instance.

When I use an incorrect username or pass I get an error right away when I try to open the connection.  When I use a good username/pass I get an error only when I try to fill a dataset with data from one of the databases.  That's when I get this named pipes error.  Does this mean its specifically a problem with the user setup on sql08?

 

by: RiteshShahPosted on 2009-05-24 at 20:33:26ID: 24464181

yes, that might a cause, try setting proper rights, you may try using "SA" user.

 

by: jay-arePosted on 2009-05-25 at 07:40:53ID: 24466845

I'm not sure if I'm setting the proper rights or not.  Sql08 already had an "sa" user setup.   When I try to check off the new databases for user SA in user mapping it gives me an error:  "Cannot use the special principal 'sa'."

I've tried lots of different user setups and they all produce the same Named Pipes error listed above...I'm sort of stuck here since I can't even get in the front door!

 

by: RiteshShahPosted on 2009-05-25 at 09:48:35ID: 24467433

why do you want to try "check off" SA? you don't need it. why don't you try using SQL Datasource connection from design time and try to connect your database from that only. once you will do it, you can copy connection string from it.

 

by: jay-arePosted on 2009-05-25 at 10:20:01ID: 24467590

I was trying to select the db I'm trying to access in user mapping.  The "customers" db isn't checked for user SA.  I don't think that matters though.  My other sysadmin "user1" has it checked and I still get the same error.

What do you mean by SQL Datasource connection?  Example?

 

by: jay-arePosted on 2009-05-26 at 05:41:16ID: 24472516

Interesting.  I added the datasource control to my webform and setup a connection string.  When tested in the wizard it works just fine, exactly like I have it on my code-behind.  However when I click "OK" to finish it says:  This server version is not supported.  You must have Microsoft SQL Server 2005 Beta 2 or later.

??

 

by: RiteshShahPosted on 2009-05-26 at 05:42:45ID: 24472534

ohhh, are you using SQL Server 2008 beta or old CTP?

 

by: jay-arePosted on 2009-05-26 at 05:44:24ID: 24472548

When I copy/paste the connectionstring it created I get this error:  Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'user1'.

Source Error:


Line 87:             Dim newcommand As New SqlCommand(query, conn)
Line 88:             newcommand.Connection = conn
Line 89:             conn.Open()
Line 90:             SqlDataAdapter1.SelectCommand.Parameters("@username").Value = TextBox1.Text
Line 91:             SqlDataAdapter1.SelectCommand.Parameters("@password").Value = TextBox3.Text
 

Source File: C:\inetpub\wwwroot\login\WebForm1.aspx.vb    Line: 89

Almost like I have the wrong credentials again but I don't.

 

by: jay-arePosted on 2009-05-26 at 05:45:52ID: 24472560

Product Version:  10.0.1600.22

Level:  RTM

Edition:  Standard Edition (64-bit)

I'm pretty sure its the full blown sql 2008.  Doesn't say beta anywhere.

 

by: RiteshShahPosted on 2009-05-26 at 05:46:02ID: 24472561

there was a bug in early SQL Server 2008, .NET framework was not able to connect it, I afraid you are out of luck if you are using it. why don't you try upgrading your SQL Server 2008???

 

by: RiteshShahPosted on 2009-05-26 at 05:46:42ID: 24472568

ohh ok. if that's RTM, don't worry.

 

by: RiteshShahPosted on 2009-05-26 at 05:48:10ID: 24472581

can you show me which connection string SQL Datasource generated?

 

by: jay-arePosted on 2009-05-26 at 05:48:13ID: 24472582

Also, the connection string the wizard created didn't have the password field.  When I add that it gives me the same old Named Pipes error.

 

by: jay-arePosted on 2009-05-26 at 05:48:55ID: 24472588

"Data Source=DA-SQL03;Initial Catalog=Customers;Persist Security Info=True;User ID=user1"
^^^ this is what it created

I added the password field to it and tested.

 

by: RiteshShahPosted on 2009-05-26 at 05:55:38ID: 24472638

can you try using following connection string?

"data source=DA-SQL03;initial catalog= Customers;password=password;persist security info=True;user id=user1;"

if above string gives you an error about user1 permission, go to your SSMS of sql server, create new login, user and use that ID/PASS in above connectionstring.


use master
CREATE LOGIN [TempUser1] WITH PASSWORD=N'password' , DEFAULT_DATABASE=[Customers], CHECK_EXPIRATION=OFF, CHECK_POLICY=ON
go

use Customers
CREATE User[TempUser1] FOR LOGIN [TempUser1]
go

your connection new string would be

"data source=DA-SQL03;initial catalog= Customers;password=password;persist security info=True;user id=TempUser1;"

 

by: jay-arePosted on 2009-05-26 at 06:56:15ID: 24473311

Ok the first string gave me the same named pipes error as before.  I created the new login anyway and used the second connection string and it still gives me the same error.

 

by: jay-arePosted on 2009-05-26 at 10:16:08ID: 24475303

I've tried enabling/disabling the different protocols.  I updated the server to sql 2008 SP1.  I tried different web.config's for my application.  I'm not sure what the problem is.  I can connect to the server, it opens the connection.  I just can't fill a dataset without getting that named pipes error...

 

by: jay-arePosted on 2009-05-27 at 13:18:17ID: 24487056

Still stuck on this.  I can open the connection to the server but I cannot fill a dataset with data from the server.  Ideas?  I'll try just about anything at this point.

 

by: jay-arePosted on 2009-05-29 at 13:45:19ID: 24506083

I opened a new question in hopes of getting more responses.

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_24448934.html

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...