VB and SQL Express Error: 40 when adding database object to VB project


  • I am currently going through the tutorials in the VB Express 2005 help file and I have reached the database tutorials. I am trying to add an SQL Server 2005 Express database object using Project/Add New Object/SQL Database.

    At first I was receiving the "Error: 26" TCP error but fixed this and then started receiving the "Error: 40" named pipes error. I have spent days searching the web for a solution but have found none that work. I have made sure external connections to the server (by both TCP and named pipes)  is available in the surface area configuration, I have run cliconfg.exe, I have checked the firewall to allow it to work, but I cannot seem to find anything that will allow me to add the empty database to the project.

    I have not even got so far as to add code so that cannot be my problem.

    My set up is XP Home SP2, VB 2005 Express, SQL Server 2005 Express. I am trying to connect to the SQL server through VB on the same computer and not over my home network. I have tried switching connection by named pipes off and only allowing TCP connections, but I still get that error. It is driving me nuts because I would really like to learn how to do it.

    What other options might I have missed that could get it working?

    Sunday, May 13, 2007 6:34 AM

All replies

  • What connection string are you using to access the database ? and whats the exact message you are getting.




    Monday, May 14, 2007 7:11 PM
  • ""Error: 40" named pipes error. "


    I've seen the named pipes error many times and it comes from a variety of issues... when they are all fixed - it works.


    Have you used you surface protection manager to enable TCPIP Communication?

    Are your database privileges and login allright?




    99 times out of 100 this is a setup problem. It's always annoying and usually I am fixing a number of things at the same time and suddenly, it's working.


    Monday, May 14, 2007 7:26 PM
  • I don't know what string I am using, I have no idea what to put in or where to put it. I have two databases set up, one refuses to start (SQLEXPRESS) and the other which works fine. I have tried to connect to database, which fixes the "Error: 40" problem, but which raises an "Error: 25 - connection string is not valid".

    I have tried connecting through tools/connect to database and pointing to my "contacts" database which is a dummy with fake phone numbers and names that I can play around with to learn SQL queries. I make sure that I use TCP/IP only in the network library, that the right database is named and when I click "okay" or "test connection" it comes up with Error: 25. the same happens if I go through the data/add new data source wizard, I can't add the working database at all.

    If I try to add a database through project/add new item/database it comes up with Error:40.

    The exact error when I do the latter is:

    Local database file

    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)

    I have made sure that TCP connection is enabled in the Surface Area Configuration, that Named Pipes are enabled but nothing seems to make it want to work.
    Friday, May 18, 2007 10:23 AM
  • Hi


    Don't know if this might be causing it, but I had similar problems once, when I deselected allow user instances (or something like it) during installation.
    I couldn't connect either until I did reinstall and selected allow user instances. After that I had no problems anymore.

    Hope this helps.

    Friday, May 18, 2007 9:26 PM