Avatar of DColin
Flag for Thailand

asked on 

Connecting to an MS SQL Express database

Hi Experts,

I am using the following code trying to connect to an MS SQL Express 2008 database. I can connect and query the database from within the SQL Server Management Studio so I think it is set up correctly. I have not set a password for the database so the credentials I am using are the windows admin credentials for the account that was used to set up the database.

The error I get when trying to connect is: Login failed for user 'admin'.

I have tried both the connection strings in the code with the same results.

Imports System.Data.Sql
Imports System.Data.SqlClient

Public Class SQLControl

    Public SQLCon As New SqlConnection With {.ConnectionString = "Server=ACERES1\SQLEXPRESS;Database=TestDb;User=admin;Pwd=Admin-123;"}
    'Public SQLCon As New SqlConnection With {.ConnectionString = "Server=ACERES1\SQLEXPRESS;Database=TestDb;User Id=admin;Password=Admin-123;"}
    Public SQLCmd As SqlCommand

    Public Function HasConnection() As Boolean


            Return True

        Catch ex As Exception

            Return False

        End Try

    End Function

End Class

Open in new window

Microsoft SQL Server 2008Microsoft SQL Server

Avatar of undefined
Last Comment
Éric Moreau

8/22/2022 - Mon