Solved

Login failed for user...

Posted on 2014-10-05
10
154 Views
Last Modified: 2014-10-08
I was under impression that this code will be using windows authentication. But I am getting:

Login failed for user 'Mike-VAIO\Mike'.

Question: How can I handle this error?
        Dim cnn As SqlConnection = New SqlConnection

        Try
            'Dim strCnn As String = "Data Source=.\SQLEXPRESS12;AttachDbFilename=NORTHWND.MDF;Integrated Security=True;Connect Timeout=30"
            Dim strCnn As String = "Server='Mike-Vaio\SQLEXPRESS12';Database='NORTHWND.MDF';User='Mike';Password='XXXXX';Trusted_Connection=False;"
            Dim cmd As SqlCommand = New SqlCommand("Select * From tblProduct", cnn)
            cnn.ConnectionString = strCnn
            cnn.Open()
            Dim dr As SqlDataReader = cmd.ExecuteReader

            If dr.HasRows Then
                MessageBox.Show("Has Records")
            Else
                MessageBox.Show("Has no Records")
            End If
            ' DataTable dt = new DataTable();
            'dt.Load(dr);
            'dataGridView1.DataSource = dt;
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            cnn.Close()
        End Try

Open in new window

0
Comment
Question by:Mike Eghtebas
  • 5
  • 3
  • 2
10 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 400 total points
ID: 40362442
Remove the single quotes the connection string.
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 40362448
Without single quotes I get other errors. I think I need to have them as they are.

For example my paswword is something XXXX;YYAA so for ; I have to use an extra \

This means I have to keep them inside single quotes (password =' XXXX\;YYAA') in order for my application not to get confused.
0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 400 total points
ID: 40362624
A connection string in not SQL. I have never seen one that uses single quotes.

And the semi-colon in the password could well be your problem.

; separates the elements of a connections string. I do not think that the escape character works in that context. This is not something I have seen in the documentation. I tried building the string with the SqlConnectionStringBuilder, a class whose purpose is to build a connection string through properties, but it has no reaction to the ;

Have you tried changing the password or logging as another user who does not have a ; in the password?
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 40362699
For single quote and ; use, please see:

Formatting Rules for Connection Strings  at http://www.connectionstrings.com/formating-rules-for-connection-strings/
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 40363742
Are you sure you are looking at the correct code? The error message indicates windows authentication being used.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 40363784
I want to use windows authentication.
0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 400 total points
ID: 40363796
With Windows authentication, you do not provide the user name and password. Its the login of the user in Windows that provides the credentials.
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 40363939
With or without, I get the same error.
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 100 total points
ID: 40364002
For the windows user, you need to add the user as a Login within SQL Server.

http://msdn.microsoft.com/en-us/library/aa337562.aspx
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 40368896
Hi James,

I got the solution. You were correct on the comments you have posted:

Dim strCnn As String = "Server=.\SQLEXPRESS12;Database=NORTHWIND.MDF';Trusted_Connection=True"
cnn.ConnectionString = strCnn
Dim cmd As SqlCommand = New SqlCommand("Select * From Products", cnn)

The letter in bold also were missing before.

Thanks,

Mike
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now