0

I'm trying to get this open source code to work in order to start building the basics for my own program. The general idea was just to create a small application that can access and manipulate SQL records, simple, right? Turns out I can't event get the testing going. I keep getting an error on runtime/debug.

The error:

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll

Additional information: 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)

Here's the code that's not working

Module modConn
    Public connDB As New SqlClient.SqlConnection
    Public comDB As New SqlClient.SqlCommand
    Public rdDB As SqlClient.SqlDataReader
    Public Item As ListViewItem
    Public SQL As String

Public Sub conecDB()

        Dim strServer As String = "127.0.0.1"    'This is the server IP/Server name.
        Dim strDbase As String = "Members_Details"   'Database name
        Dim strUser As String = "CENSORED"     'Database user
        Dim strPass As String = "CENSORED"    'Database password

        If connDB.State <> ConnectionState.Open Then connDB.ConnectionString = "Server=" & strServer.Trim & ";Database=" & strDbase.Trim & ";User ID=" & strUser.Trim & ";Password=" & strPass
        If connDB.State <> ConnectionState.Open Then connDB.Open

    End Sub

The error is referring to the last line connDB.Open.

I've verified the SQL server is running. It's accepting all protocols (TCP/IP, Named Pipes & Shared Memory). The server is MS Server Express + SQL Server Management Studio... And I'm able to sign in and manipulate the database using the SQL Server Managment Studio by using the same login credentials as the program, so I'm pretty sure it's the programs code that's wrong.

My guess is that the area of the code that it brings everything together is wrong; perhaps a character or something -- I'm referring to

If connDB.State <> ConnectionState.Open Then connDB.ConnectionString = "Server=" & strServer.Trim & ";Database=" & strDbase.Trim & ";User ID=" & strUser.Trim & ";Password=" & strPass
If connDB.State <> ConnectionState.Open Then connDB.Open  

Any help would be greatly appreciated. I'm relatively new to programming and this is more of a challenge then anything else. Please, in your replies try to keep it structures similarly to what I've got already, if you can.

I'm using Visual Basic Studio on .net 4.5. Thanks in advance!

edtheprogrammerguy
  • 5,957
  • 6
  • 28
  • 47
user2980316
  • 139
  • 1
  • 3
  • 13

1 Answers1

0

thanks for your usual fast replies. I've managed to work a solution out when I decided to dig deeper into Mitch Wheat's recommendation to verify the configuration of the SQL Server. It turns out the issue was with the SQL Server configuration. This excellent site had a solution to that as well, thanks! Much appreciated!

The solution to me problem was this. (Link)

Community
  • 1
  • 1
user2980316
  • 139
  • 1
  • 3
  • 13
  • Copy the content from the linked page to your answer. That way, in case the linked page is ever removed, your solution is still here. – Trojan Jan 08 '14 at 06:59