Results 1 to 14 of 14

Thread: [RESOLVED] Unable to connect to MS SQL express

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    320

    Resolved [RESOLVED] Unable to connect to MS SQL express

    I have used to code from a YouTube VB.Net Tutorial and I cannot connect. I am using Microsoft Visual Studio Community 2017 and Micosoft SQL Server Management Studio V17.7. I have checked the code But have been unable to see the problem Here is the code and the error message
    Code:
     Imports System.Data.SqlClient
    
    Public Class SQLControl
        Private DBCon As New SqlConnection("Server= BILLS_LAPTOP\SQLEXPRESS01:Database = Maint1;User = Maint1:Pwd = Password1;")
        Private DBcmd As SqlCommand
        'BILLS_LAPTOP\SQLEXPRESS01
        ' DB Data
        Public DBDA As SqlDataAdapter
        Public DBDT As DataTable
    
    
        ' Qury Parameters
        Public Params As New List(Of SqlParameter)
    
        'Query Statistics
        Public RecordCount As Integer
        Public Exception As String
    
        Public Sub New()
    
        End Sub
        'Allow Connection String Override
        Public Sub New(ConnectionString As String)
            DBCon = New SqlConnection(ConnectionString)
        End Sub
        'Execute Query Sub
        Public Sub ExecQuery(Query As String)
            'Reset Query Stats
            RecordCount = 0
            Exception = ""
            Try
                DBCon.Open()
    
                'Creat DB Command
                DBcmd = New SqlCommand(Query, DBCon)
    
                'Load Parans into DB Command
                Params.ForEach(Sub(p) DBcmd.Parameters.Add(p))
                'Clear Param List
                Params.Clear()
    
                'Execute Command & Fill Dataset
                DBDT = New DataTable
                DBDA = New SqlDataAdapter(DBcmd)
                RecordCount = DBDA.Fill(DBDT)
    
            Catch ex As Exception
                'Capture Error
                Exception = "ExceQuery Error: " & vbNewLine & ex.Message
    
    
            Finally
                'Close Connection
                If DBCon.State = ConnectionState.Open Then DBCon.Close()
    
    
            End Try
        End Sub
        'Add Params
        Public Sub AddParam(name As String, value As Object)
            Dim NewParam As New SqlParameter(name, value)
            Params.Add(NewParam)
        End Sub
    
        'Error Checking
        Public Function hasexception(Optional Report As Boolean = False) As Boolean
            If String.IsNullOrEmpty(Exception) Then Return False
            If Report = True Then MsgBox(Exception, MsgBoxStyle.Critical, "Exception:")
            Return True
    
        End Function
    
    
    End Class
    Name:  SQL Error.jpg
Views: 736
Size:  12.5 KB
    Name:  SQLDB.jpg
Views: 577
Size:  14.8 KB

    Thanks for any help you can give me. I am new to both VB2017 and SQL DB's

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Unable to connect to MS SQL express

    I won't attempt to assist beyond this single reply, because there are so many potential issues that can be at play here that are nearly impossible to diagnose over forum posts without a tremendous amount of repeated "did you check this?"

    That being said, the screenshot seems to indicate that your database name is "HiTech", but your connection string seems to be attempting to connect to a database called "Maint1"

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    320

    Re: Unable to connect to MS SQL express

    Sorry I was doing editing and made a mistake I changed it back to HiTech And got the Same error as before I started editing.

    Thanks

  4. #4
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,440

    Re: Unable to connect to MS SQL express

    Is it the colon instead of semicolon?
    https://www.connectionstrings.com/sq...rver-instance/

    _LAPTOP\SQLEXPRESS01:Database =
    :Pwd =
    Last edited by Zvoni; Jun 13th, 2018 at 03:36 PM.
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    320

    Re: Unable to connect to MS SQL express

    Thanks
    I missed that but changing it did not help I still get the same error

    Thanks

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    320

    Re: Unable to connect to MS SQL express

    Ops I missed the first : I changed it and now I get this error.


    Name:  QueryError.jpg
Views: 393
Size:  7.0 KB

    Thanks for finding some of this But I have never used Mssql before yesterday.

  7. #7
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,398

    Re: Unable to connect to MS SQL express

    Try this:

    Code:
    Private DBCon As New SqlConnection("Server=BILLS_LAPTOP\SQLEXPRESS01;Database=Maint1;User=Maint1;Pwd=Password1;")

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    320

    Re: Unable to connect to MS SQL express

    Same error
    The Database is named HiTech I don't know what other information to give to you folks to help me


    Thanks

  9. #9
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,398

    Re: Unable to connect to MS SQL express

    Try it without the last semicolon. The error indicates that the password is incorrect.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    320

    Re: Unable to connect to MS SQL express

    Well that also did nothing different than the last error message

  11. #11
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,398

    Re: Unable to connect to MS SQL express

    Can you log in to SQL Server Management manually using the same credentials you are using in the connection string?

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    320

    Re: Unable to connect to MS SQL express

    No I had been logging with my Windows Authorization here's the 2 screens and the errors

    Name:  ServerErrro.jpg
Views: 453
Size:  14.2 KB
    Name:  Login.jpg
Views: 557
Size:  15.7 KB
    I'm days new to MSSQL
    not sure how to fix this from Here

    Thanks

  13. #13
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,398

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    320

    Re: Unable to connect to MS SQL express

    Thank for everyones help it was the SQL's login type to be setup
    Thanks
    Alfarata

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width