troubleshooting Question

Connecting to an MS SQL Express database

Avatar of DColin
DColinFlag for Thailand asked on
Microsoft SQL Server 2008Microsoft SQL Server
2 Comments1 Solution63 ViewsLast Modified:
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
Senior Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros