Error Code -2146232060 RRS feed

  • Question

  • Imports System.Data.SqlClient
    Imports System.Data.DataTable
    Imports MySql.Data.MySqlClient
    Public Class Form1

        Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click

        End Sub

        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        End Sub

        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim connection As New SqlConnection("Server = localhost;user=root;password=msrp;Database = hotel")

            Dim command As New SqlCommand("select * from guest where username = @username and password = @password", connection)

            command.Parameters.Add("@username", SqlDbType.VarChar).Value = TextBoxUsername.Text
            command.Parameters.Add("@password", SqlDbType.VarChar).Value = TextBoxPassword.Text

            Dim adapter As New SqlDataAdapter(command)

            Dim table As New DataTable()


            If table.Rows.Count() <= 0 Then

                MessageBox.Show("Username or password not correct")


                MessageBox.Show("Login Successful")

            End If

        End Sub

        Private Sub TextBoxUsername_TextChanged(sender As Object, e As EventArgs) Handles TextBoxUsername.TextChanged

        End Sub
    End Class

    The error says:

    System.Data.SqlClient.SqlException occurred
      Message=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=.Net SqlClient Data Provider
           at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
           at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
           at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover, Boolean isFirstTransparentAttempt, SqlAuthenticationMethod authType, Boolean disableTnir)
           at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover, Boolean isFirstTransparentAttempt, Boolean disableTnir)
           at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
      InnerException: System.ComponentModel.Win32Exception
           Message=The system cannot find the file specified

    Friday, October 13, 2017 3:06 AM

All replies

  • Hi shawanish8,

    According to your description, please confirm that the username and password are correct firstly, and then try to restart your MSSQLSERVER service and look if it can work fine.

    The detailed step is:
    1.Go to control panel. for services.
    3.Open Local services window from your search results
    4.Restart your MSSQLSERVER service.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    • Proposed as answer by Stanly Fan Thursday, October 19, 2017 8:03 AM
    Monday, October 16, 2017 2:41 AM