title: Connect to SQL with runas /netonly
body: <p>I'm trying to connect to a SQL database within my vb.net form.</p>
  
  <p>I usually connect to SQL using a .bat file which looks something like the following:</p>
  
  <p>Runas /netonly /user:<strong>domain</strong>\ <strong>username</strong> "C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe"</p>
  
  <p>I found a similar question <a href="https://stackoverflow.com/questions/757857/how-to-build-runas-netonly-functionality-into-a-c-net-winforms-program">here</a></p>
  
  <p>I've searched for the vb.net alternative but I can't anything other than that.</p>
  
  <p>My code look something like</p>
  
  <pre><code>Imports System.Data.SqlClient
  
  Public Class Form1
  
  Dim con As SqlConnection = New SqlConnection("Server= ;Database= ;User Id= ; Password= ")
  Dim cmd As SqlCommand = New SqlCommand("Select top 1 from table (NOLOCK)")
  
  Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  
      If con.State = ConnectionState.Closed Then con.Open()
      Dim sdr As SqlDataReader = cmd.ExecuteReader()
      While sdr.Read = True
          MessageBox.Show(sdr.Item("Column1") &amp; " " &amp; sdr.Item("Column2"))
      End While
      sdr.Close()
  
  End Sub
  End Class
  </code></pre>
  
  <p>I get an error due to invalid user when I fill me details in.</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p><em>Sorry if I've not done this correctly, long time lurker first time poster</em></p>
  
  <p>Thanks</p>