none
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()

            adapter.Fill(table)

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

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

            Else

                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
      Class=20
      ErrorCode=-2146232060
      HResult=-2146232060
      LineNumber=0
      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)
      Number=2
      Server=""
      Source=.Net SqlClient Data Provider
      State=0
      StackTrace:
           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
           ErrorCode=-2147467259
           HResult=-2147467259
           Message=The system cannot find the file specified
           NativeErrorCode=2
           InnerException: 

    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.
    2.search for services.
    3.Open Local services window from your search results
    4.Restart your MSSQLSERVER service.

    Best Regards,

    Cherry


    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 MSDNFSF@microsoft.com.

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