1 Replies - 2157 Views - Last Post: 21 August 2009 - 08:02 AM Rate Topic: -----

#1 workid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 23-July 09

Help connecting to SQL database in feedback form

Posted 21 August 2009 - 05:27 AM

Hi
I have created a kind of feedback form and want it to insert the data into a database table and also email the data to a email address.

I'm new to all this and have followed a tutorial to do this, when i enter the data into the form and click send i get the following server 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)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: 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)

Source Error:

Line 31: .Add(New SqlParameter("@Date", DateTime.Now()))
Line 32: End With
Line 33: MyConn.Open()
Line 34: Cmd.ExecuteNonQuery()
Line 35: lblResponse.Text = "Your information has been successfully received. 'We will get back to you as soon as possible"

Obviously its not connecting to the database, as i have followed a tutorial it may need some more code added to work for my database. The databse and server is just on my laptop at the moment as im designing it using Web developer 2008. Here is the code i have created for the page to connect:

Sub doInsert()

		Dim strConn As String = "server=it-laptop-07;database=bqTravel.mdf;"
		Dim MySQL As String = "Insert into callBack (Name, Email, phoneNumber, HolidayType, Feedback, Date, Followup) " & _
		 "Values (@Name, @Email, @phoneNumber, @Holiday @Feedback, @Date)"
		Dim MyConn As New SqlConnection(strConn)
		Dim Cmd As New SqlCommand(MySQL, MyConn)
		With Cmd.Parameters
			.Add(New SqlParameter("@Name", txtName.Text))
			.Add(New SqlParameter("@Title", txtEmail.Text))
			.Add(New SqlParameter("@phoneNumber", txtNumber.Text))
			.Add(New SqlParameter("@Holiday", ddlHolidayType.Text))
			.Add(New SqlParameter("@Feedback", txtComments.Text))
			.Add(New SqlParameter("@Date", DateTime.Now()))
		End With
		MyConn.Open()
		Cmd.ExecuteNonQuery()
		lblResponse.Text = "Your information has been successfully received. 'We will get back to you as soon as possible"
		MyConn.Close()
	End Sub



The name of my laptop is it-laptop-07 so i have put this as the name of the server, or is this wrong?

as you can tell im new to this and any help would be appreciated.

Thanks
Pete

This post has been edited by workid: 21 August 2009 - 05:28 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Help connecting to SQL database in feedback form

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Help connecting to SQL database in feedback form

Posted 21 August 2009 - 08:02 AM

Your connection string is incorrect.

Sql Server connection string
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1