Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
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 February 24th, 2006, 05:03 AM
Authorized User
 
Join Date: Feb 2006
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with my sql server express connection

hi guys,
i very happy that i found this forum which discuss ASP.net.
i am new to ASP.net 2.0 and some serious help. when i debug my application and try to insert data an error occur saying:

"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)"

the code that i have used to submit data is as follow:

Imports System.Data.SqlClient
...
  Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

      Dim objConn As SqlConnection
      Dim objCmd As SqlCommand

objconn = New SqlConnection("Server=localhost; Database=ecb;user
ID='';Password=''")

objCmd = New SqlCommand("INSERT INTO staff (firstname, surname) VALUES (@firstname, @surname,)", objConn)

objCmd.Parameters.Add("@FirstName", Data.SqlDbType.VarChar).Value = txtFirstName.Text
objCmd.Parameters.Add("@Surname", Data.SqlDbType.VarChar).Value = txtSurname.Text

objConn.Open()
objCmd.ExecuteNonQuery()
objConn.Close()

can anyone help? thank you in advanced

 
Old February 24th, 2006, 01:16 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I think this is caused by the fact you're using localhost instead of (local).

This "problem" was first introduced with Windows Server Pack 2 (I believe, or SQL Service Pack 3)

Simply change this:

Server=localhost

to

Server=(local)

Can you please not cross-post your messages? Your message will be read anyway....

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old February 24th, 2006, 03:21 PM
Authorized User
 
Join Date: Feb 2006
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Default

to Imar:

Thank you very much for replying but the problem seems not to be solved and i still recieve the same message. could you please tell me if the code i have written is correct or not. probably the problem is from the code.
thanks.:)

 
Old February 24th, 2006, 07:47 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Take a look here:

http://www.connectionstrings.com/

Depending on your database, click one of the nodes for an example of a good connection string. You may need something like:

"Data Source=ServerName;Initial Catalog=DatabaseName;User Id=UserName;Password=Password;"

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old February 25th, 2006, 05:46 PM
Authorized User
 
Join Date: Feb 2006
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you very much Imar for the help. However, i still have the same problem and the same messge error 40.


 
Old February 26th, 2006, 01:31 AM
Authorized User
 
Join Date: Jul 2005
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Did you install SQL Server Configuration Manager?

Run this problem and go to SQL Server 2005 Network Configuration.

You'll see 4 protocol names.
Make sure TCP/IP and Named Pipes are enabled.

Besides, try the following
localhost\sqlexpress as the Data source

Hope that helps...

 
Old February 26th, 2006, 07:34 PM
Authorized User
 
Join Date: Feb 2006
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you very much for your help g2000. it seems that you have solved most of the problem. i now do not receive the error message 40, however,whenever i like to excute the statement another error message comes up and say: Login failed for user ''. The user is not associated with a trusted SQL Server connection. i can't remember if i typed a username and a password first i install sql server. but i am pretty sure that i have used Windows authentication. i tried to remember and i typed some user name and password in the connection declaration (objconn = New SqlConnection("Server=localhost; Database=ecb;user
ID='sa';Password='dgfsdle34'")in hope to solve the problem but it sends back a message saying login failed for user 'sa'.
can you help?


 
Old February 27th, 2006, 10:00 AM
Authorized User
 
Join Date: Jul 2005
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Did you install Microsoft SQL Server Management Studio Express? It's a free and handy tool for admin purpose.

Run it and look for Object Explorer(lower left hand corner),
Security > sa (that's the one you told me) > double click > User Mapping

Just click the database you wanna have connection with and choose the role membership for that.

Hope that helps...

 
Old February 28th, 2006, 08:20 AM
Authorized User
 
Join Date: Feb 2006
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi g2000:

thank you for your help. Anyway it sounds not help, however my question here can i uninstall SQL server express edition while keeping hold of the tables that i have done (is quite important)? and then reinstall the application just to make sure that from the authentication level!!!

do you thing is a good solution? if yes would you please tell me how to keep the tables and uninstall the application?

Many thanks saif44

 
Old June 13th, 2006, 05:07 PM
Registered User
 
Join Date: Jun 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to akj004
Default

 Hi,

 Please try this. Select the View menu->Database Explorer->New Connection. On the wizard appeared specify your the database name and server on which you are going to use. Test connection. I fconnection succeed, it will appear on database Explorer on right. Right click on that select the property. Copy the connection string and use it in your code. If not works then set the permission on the server side.

 It can be done by right click database, select permissions,add select the user there are certain permissions can be seen check on each. Then try on the front end






Similar Threads
Thread Thread Starter Forum Replies Last Post
Remote connection error with SQL Server Express DudeBori82 SQL Server 2005 4 April 12th, 2009 01:51 AM
SQL Server Express Connection String dkaufmann VB Databases Basics 4 November 3rd, 2006 01:48 PM
i have a problem in SQL server express saif44 SQL Language 1 March 1st, 2006 06:25 PM
Accessing a SQL Server Express DB thru VB Express djelavic SQL Server 2005 2 February 21st, 2006 07:53 PM
SQL Server 2005 Express Problem asped_man BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 3 November 29th, 2005 05:07 AM





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