I'm trying to connect to a SQL database within my vb.net form.
I usually connect to SQL using a .bat file which looks something like the following:
Runas /netonly /user:domain\ username "C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe"
I found a similar question here
I've searched for the vb.net alternative but I can't anything other than that.
My code look something like
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") & " " & sdr.Item("Column2"))
End While
sdr.Close()
End Sub
End Class
I get an error due to invalid user when I fill me details in.
Any help would be greatly appreciated.
Sorry if I've not done this correctly, long time lurker first time poster
Thanks