SQLOLEDB Connection Error
As Chapter 2 I tried to connect SQL Database using below connection string and that was not successful. I' using SQL 2005 Express edition and visual basic 2005 professional edition. My SQL Server Named Instants is ".\Local" and i already have database i was created named "cash". here is my code:
***** This Access Code is working and below SQL connection code not working *******
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strOleDbConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Users\Sagara\Documents\Visual Studio 2005\Projects\OleDB_Proj\ProjectTimeTracker.MDB;"
Dim Conn As OleDbConnection = New OleDbConnection(strOleDbConn)
Try
Conn.Open()
MsgBox(Conn.State.ToString)
Catch ex As Exception
Finally
Conn.Close()
MsgBox(Conn.State.ToString)
Conn.Dispose()
Conn = Nothing
End Try
End Sub
**** This is the code not working ********
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'TODO : Please Check with this code wrox forum
Dim strSQLOLE As String = "Provider=SQLOLEDB;Data Source=.\Local;Database=Cash;"
Dim Conn As OleDbConnection = New OleDbConnection(strSQLOLE)
Try
Conn.Open()
MsgBox(Conn.State.ToString)
Catch ex As Exception
MsgBox(ex.ToString)
Finally
Conn.Close()
MsgBox(Conn.State.ToString)
Conn.Dispose()
Conn = Nothing
End Try
End Sub
|