VB 2008 Samples

Errors in Microsoft Official VB 2008 Samples

Page 1 of 1

6 Replies - 16188 Views - Last Post: 23 July 2008 - 03:34 PM Rate Topic: -----

#1 deHunCut   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-June 08

VB 2008 Samples

Post icon  Posted 26 June 2008 - 08:05 AM

I downloaded VB 2008 Express with SQL Express Compact.
Then I downloaded the Samples from Microsoft.
Followed to instructions for CreateDB sample and clicked on Create Database button got an error message
"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 connection to SQL Server)
	Protected Const SqlConnectionString As String = _
		"Server=(local)" & _
		"DataBase=;" & _
		"Integrated Security=SSPI"
...
 Private Sub CreateDatabase()
		Dim sqlStatement As String = _
			"IF EXISTS (" & _
			"SELECT * " & _
			"FROM master..sysdatabases " & _
			"WHERE Name = 'HowToDemo')" & vbCrLf & _
			"DROP DATABASE HowToDemo" & vbCrLf & _
			"CREATE DATABASE HowToDemo"

		' Display a status message saying that we're attempting to connect.
		' This only needs to be done the very first time a connection is
		' attempted.  After we've determined that MSDE or SQL Server is
		' installed, this message no longer needs to be displayed.
		Dim statusForm As New Status()
		If Not didPreviouslyConnect Then
			statusForm.Show("Connecting to SQL Server")
		End If

		' Attempt to connect to the SQL server instance.  
		Try
			' The SqlConnection class allows you to communicate with SQL Server.
			' The constructor accepts a connection string as an argument.  This
			' connection string uses Integrated Security, which means that you 
			' must have a login in SQL Server, or be part of the Administrators
			' group for this to work.
			Dim connection As New SqlConnection(connectionString)

			' A SqlCommand object is used to execute the SQL commands.
			Dim cmd As New SqlCommand(sqlStatement, connection)
		  ' Open the connection, execute the command, and close the 
			' connection. It is more efficient to ExecuteNonQuery when data is 
			' not being returned.
			connection.Open()

...
What is the right connection string for the Local SQL Compact?

Is This A Good Question/Topic? 0
  • +

Replies To: VB 2008 Samples

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14244
  • View blog
  • Posts: 57,145
  • Joined: 12-June 08

Re: VB 2008 Samples

Posted 26 June 2008 - 11:55 AM

try 'localhost'
Was This Post Helpful? 0
  • +
  • -

#3 deHunCut   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-June 08

Re: VB 2008 Samples

Posted 27 June 2008 - 01:35 AM

View Postmodi123_1, on 26 Jun, 2008 - 11:55 AM, said:

try 'localhost'

Thanks for the advice, did not work.
Neither as localhost nor as (localhost)
However if I change to \\localhost\sqlexpress
the error message changes to ...(provider:Named Pies Provider,error: 5 - Invalid parameter(s) found

This post has been edited by deHunCut: 27 June 2008 - 04:06 AM

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14244
  • View blog
  • Posts: 57,145
  • Joined: 12-June 08

Re: VB 2008 Samples

Posted 27 June 2008 - 07:21 AM

try the name of your pc..
Was This Post Helpful? 0
  • +
  • -

#5 deHunCut   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-June 08

Re: VB 2008 Samples

Posted 27 June 2008 - 09:08 AM

View Postmodi123_1, on 27 Jun, 2008 - 07:21 AM, said:

try the name of your pc..

Oh sorry, for not saying.
I did that . error message invalid parameter same as \\localhost\sqlexpress
Was This Post Helpful? 0
  • +
  • -

#6 Peter3076   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 05-July 08

Re: VB 2008 Samples

Posted 05 July 2008 - 09:58 AM

View PostdeHunCut, on 27 Jun, 2008 - 09:08 AM, said:

View Postmodi123_1, on 27 Jun, 2008 - 07:21 AM, said:

try the name of your pc..

Oh sorry, for not saying.
I did that . error message invalid parameter same as \\localhost\sqlexpress


This problem is know by Microsoft. I have readed. Localhost has to be changed in local. Then, they say, it works.
Was This Post Helpful? 0
  • +
  • -

#7 Noisten   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 23-July 08

Re: VB 2008 Samples

Posted 23 July 2008 - 03:34 PM

I don't know if you have solved this issue yet since it was posted on the 26th of June, but while I was searching for VB 2k8 Samples to connect to SQL Server I noticed this post didn't have a solution and thought I'd provide some help.

The error you are recieving, ""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 connection to SQL Server)" is returned when the SQL Server 2005 Instance you are connecting to is configured to accept only local connections.

To correct your problem you need to enable local and remote connections.

By default SQL Server 2005 Express does not have this enabled.

To enable this, from the SQL Server 2005 Start Menu goto Configuration tools -> SQL Server Surface Area Configuration.

Click on "Surface Area Configuration for Services and Connections" under "Configure Surface Area for localhost".

Expand the SQL Server instance you wish to configure, expand Database Engine, select Remote Connections.

Change the setting from "Local connections only" to "Local and remote connections" select the protocol relevant to your environment and click ok.

You will need to restart SQL Server before this change takes affect.

If you have SQL Server Books On-Line installed the help is located at "ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/uirfsql9/html/252174de-a9b5-48bd-ae07-2533584282da.htm"
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1