Hi, using VB 2008 Express, I have a button on a form which is to use a datareader to loop through all the records in a file. When I try to run it I get a message indicating it could not connect. I assume something is wrong with my connection string but I don't know what. I know the path name is correct, and I know my database does not require a password. I have tried it with and without USER ID and PASSWORD. I don;t know where to look next. Any help is appreciated.
Thanks,
Bill P.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sConnection As String = "server=(local);uid=test;pwd=PassWord;database=C:\Documents and Settings\Compaq_Owner\My Documents\Visual Studio 2008\Projects\Medications\Medications\medications.sdf"
Dim objCommand As New SqlCommand
objCommand.CommandText = "Select doctor From Doctors"
objCommand.Connection = New SqlConnection(sConnection)
objCommand.Connection.Open()
Dim objDataReader As SqlDataReader = objCommand.ExecuteReader()
If objDataReader.HasRows Then
Do While objDataReader.Read()
Console.WriteLine(" Your name is: " & objDataReader(0))
Loop
Else
Console.WriteLine("No rows returned.")
End If
objDataReader.Close()
objCommand.Dispose()
End Sub
End Class