Click to See Complete Forum and Search --> : Problems to Connect to access fro vb.net


sam_ccld
June 20th, 2003, 12:41 PM
Problems connecting to a DB
Hi;
I am new to VB.Net
What I am trying to do is to connect to my Access Database Using the ADO.NET DataReader, I am getting an error message saying that there is a problem with the connection string.
I have a feeling that it is not the problem, honestly i can not figure it out here is the code



' MsgBox(txtLogin.Text & " " & txtPassword.Text)
Dim MyPath As String
MyPath = CurDir()
Dim chemin As String
chemin = MyPath & "\carnet.mdb"

' Dim sConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
' "Data Source=" & chemin

Dim sConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;User Id=; Password=; Data Source=" & chemin & ";"
MsgBox(sConnString)
Dim SqlConn As New System.Data.SqlClient.SqlConnection(sConnString)
<========= Here is the line that is causing th problem
Dim strSQL As String = "SELECT * FROM user"
Dim SqlComm As New System.Data.SqlClient.SqlCommand(strSQL, SqlConn)
Dim DR As System.Data.SqlClient.SqlDataReader
'now we "TRY" to open the connection
Try
SqlConn.Open()
'ok we made it this far now we execute the query
DR = SqlComm.ExecuteReader
' 'now we can loop through the records..
Do While DR.Read()
If (DR("login") = txtLogin.Text And DR("password") = txtPassword.Text) Then
MsgBox(DR("login") & " Here you are")
End If
Loop
Catch ex As System.Data.SqlClient.SqlException
' 'there was an error so msgbox it...
MsgBox(ex.ToString())
Finally
'we close everything (if its open)
If DR.IsClosed = False Then DR.Close()
SqlComm.Dispose()
If SqlConn.State <> ConnectionState.Closed Then SqlConn.Close()
SqlConn.Dispose()

End Try

--------------------------------------------------------------------------------


Can any one help, and if there is a syntax or a logical problem in this code please no not hesitate to correct it

=====================
THANK YOU IN ADVANCE FOR TAKING TIME TO REAT MY THREAD

YOURS SAMY



Here is the exact error message

An unhandled exception of type 'System.ArgumentException' occurred in system.data.dll

Additional information: Unknown connection option in connection string: provider.

newvisva
June 22nd, 2003, 01:32 AM
If I'm not mistaken SqlClient should only be used for SQL Server. I suggest that u use ADODB by selecting from the refrence.

If u need the code ADODB then I'll post it here.