We help IT Professionals succeed at work.
Get Started

Connecting to an MS SQL Express database

Last Modified: 2016-02-19
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

Watch Question
Senior Developer
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE