Reputation: 4997
Just after installing my application, I need to attach my DB to SQL server. I am using following code for it.
Dim cmd As New SqlCommand()
Dim vrMyConString As String = "Data Source=.\SQLExpress; INITIAL CATALOG=master; uid=sa; pwd=sa;"
Dim conn As System.Data.SqlClient.SqlConnection = New SqlConnection(vrMyConString)
cmd.CommandText = "sp_attach_db 'e:\dbTest.mdf', 'e:\dbTest.ldf'"
' conn.ConnectionString = "Data Source=.\SQLExpress; INITIAL CATALOG=master; uid=sa; pwd=sa;"
conn.Open()
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = conn
cmd.executenonquery()
It returns an error: "Login failed for user 'sa'. The user is not associated with a trusted SQL Server connection."
Please advise what do I need to do. Thanks
Upvotes: 0
Views: 1182
Reputation: 24032
Usually this is because, by default, mixed authentication mode is disabled. If it is, make sure your login credentials are correct.
Here is a link that covers how to enable mixed authentication http://support.webecs.com/KB/a374/how-do-i-configure-sql-server-express-to-enable-mixed.aspx
Upvotes: 1