?
Solved

Login failed for user...

Posted on 2014-10-05
10
Medium Priority
?
161 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 40

Accepted Solution

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

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 1600 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

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
 
LVL 34

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 1600 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 34

Author Comment

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

Assisted Solution

by:CodeCruiser
CodeCruiser earned 400 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 34

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

777 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