MS SQL Server

AFterlife

Well-known member
Joined
Dec 21, 2003
Messages
73
Ok. This is my first time working with SQL Server. I was under the impression that using a SQL Connection that you dont need a provider for it. But i get this error.

An OLE DB Provider was not specified in the ConnectionString. An example would be, Provider=SQLOLEDB;.

So why does it do that.

Code:
Dim da As OleDb.OleDbDataAdapter
        Dim oSQLConn As SqlConnection = New SqlConnection

        oSQLConn.ConnectionString = "Data Source=(local);" & _
                                    "Initial Catalog=dbCustomers;" & _
                                    "Integrated Security=SSPI"


        Dim myCustomer As New CCustomer
        With myCustomer
            .FirstName = txtFirstName.Text
            .LastName = txtLastName.Text
            .City = txtCity.Text
            .ZipCode = txtZipCode.Text
            .Country = txtCountry.Text

        End With

        Dim SQL As String = "INSERT INTO dbCustomers.tblCustomers (CustomerID, FirstName, LastName, Address, City, ZipCode, Country) VALUES (" _
        & "" & myCustomer.FirstName & "" & " ," & "" & myCustomer.LastName & "" & " ," & "" _
        & myCustomer.Address & "" & " ," & "" & myCustomer.City & "" & " ," & "" & myCustomer.ZipCode & "" & " ," & "" & myCustomer.Country & "" & ")"

        da = New OleDb.OleDbDataAdapter(SQL, oSQLConn.ConnectionString)

Oops.. I think Im ok.. I forgot about the command object and executing non querys.
 
Last edited by a moderator:
If you are dealing with SQL use the System.Data.SqlClient.SqlConnection object rather than an OleDBConnection object. The OleDb version will always require a provider the SqlClient version can only be used with SQL and therefore doesnt need a provider.
 
I believe that you call OleDbDataAdapter with SqlConnection, also make sure as PlausiblyDamp said, import only System.Data.SqlClient.

SUM: stick to one provider ;)
 
Back
Top