title: VB .NET ODBC Connection with Windows authentication
body: <p>I am using Windows Server Datacenter. I am working on VB .Net 2010 Express Edition with .Net version 4.0.</p>
  
  <p>I am having issue of making ODBC connection with SQL Server on VB .Net. </p>
  
  <p>Here is my code snippet to connect with database.</p>
  
  <pre><code>Imports System.Data.Odbc
  
  Public Class Form1
  
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          Dim cn As Odbc.OdbcConnection
          cn = New Odbc.OdbcConnection("DRIVER={SQL Server};SERVER=&lt;machine_name&gt;\SQLEXPRESS;UID=&lt;machine_name&gt;\&lt;windows_username&gt;;" &amp; _
                                 "PWD=&lt;windows_password&gt;;DATABASE=testdb;")
  
          Dim mystring As String = "select * from Customers"
          Dim cmd As Odbc.OdbcCommand = New Odbc.OdbcCommand(mystring)
          cn.Open()
          MsgBox("Connected")
          cn.Close()
      End Sub
  End Class
  </code></pre>
  
  <p>Running this program I am getting below error:</p>
  
  <pre><code>ERROR [28000] [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user '&lt;machine_name&gt;\&lt;windows_username&gt;'.
  </code></pre>
  
  <p>Primarily the issue sounds that the username and password provided is wrong. But I am using same username and password to access the system.</p>
  
  <p>I think the issue is the way I have provided username and password to the connection string. </p>
  
  <p>I have tried it by making DNS connection with the same database. I have created System DNS,  and trying to connect with below connection string.</p>
  
  <pre><code>DRIVER={SQL Server};DNS=&lt;DNS_name&gt;;UID=&lt;windows_username&gt;;PWD=&lt;windows_password&gt;;
  </code></pre>
  
  <p>In this case I am getting following error.</p>
  
  <pre><code>ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
  </code></pre>
  
  <p>I have checked in both 32 bit and 64 bit DNS, the DNS name specified is available in both versions.</p>
  
  <p>Where I am wrong to make connection? Is there any problem in specifying connection string? If so then please suggest correct connection string to make ODBC connection of SQL Server in VB.Net 2010 Express Edition .</p>