473,383 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Oledb VS Sql. Oledb works with Sql Server; Sql doesn't...why

I'm using the System.Data.OleDb for SQL Server access, and it works
perfectly. However, I see a lot of code examples that use
System.Data.SqlClient. So I try it and it and can't get it to work.

Here are my samples. Why does Oledb work and SqlClient not?

' At the top of the module:
Imports System.Data.SqlClient

Dim cn As SqlConnection = New SqlConnection("<ConnString>") '< -- error
here
cn.Open()
Dim cmd As SqlCommand = New SqlCommand("MyStoredProc", cn)
cmd.CommandType = CommandType.StoredProcedure
Dim param As SqlParameter = cmd.Parameters.Add("@Param", "<val>")
Dim dr As SqlDataReader
dr = cmd.ExecuteReader()

When I run it, I get an error on the Dim cn As SqlConnection line:
--------------------------------------
An unhandled exception of type 'System.ArgumentException' occurred in
system.data.dll
Additional information: Keyword not supported: 'provider'.
--------------------------------------
But this works fine.

' At the top of the module:
Imports System.Data.OleDb

Dim cn As OleDbConnection = New OleDbConnection("<ConnString>")
cn.Open()
Dim cmd As OleDbCommand = New OleDbCommand("MyStoredProc", cn)
cmd.CommandType = CommandType.StoredProcedure
Dim param As OleDbParameter = cmd.Parameters.Add("@Param", "<val>")
Dim dr As OleDbDataReader
dr = cmd.ExecuteReader()

Should I continue to use SystemData.OleDb for Sql Server access? Why am I
getting an error with SqlClient?

Thanks.


Mar 28 '06 #1
5 1653
Hi,

The sqlclient class only works with sql server. You do not
need the provider in the connection string.

Ken
---------
"mrmagoo" <-> wrote in message news:uT**************@TK2MSFTNGP12.phx.gbl...
I'm using the System.Data.OleDb for SQL Server access, and it works
perfectly. However, I see a lot of code examples that use
System.Data.SqlClient. So I try it and it and can't get it to work.

Here are my samples. Why does Oledb work and SqlClient not?

' At the top of the module:
Imports System.Data.SqlClient

Dim cn As SqlConnection = New SqlConnection("<ConnString>") '< -- error
here
cn.Open()
Dim cmd As SqlCommand = New SqlCommand("MyStoredProc", cn)
cmd.CommandType = CommandType.StoredProcedure
Dim param As SqlParameter = cmd.Parameters.Add("@Param", "<val>")
Dim dr As SqlDataReader
dr = cmd.ExecuteReader()

When I run it, I get an error on the Dim cn As SqlConnection line:
--------------------------------------
An unhandled exception of type 'System.ArgumentException' occurred in
system.data.dll
Additional information: Keyword not supported: 'provider'.
--------------------------------------
But this works fine.

' At the top of the module:
Imports System.Data.OleDb

Dim cn As OleDbConnection = New OleDbConnection("<ConnString>")
cn.Open()
Dim cmd As OleDbCommand = New OleDbCommand("MyStoredProc", cn)
cmd.CommandType = CommandType.StoredProcedure
Dim param As OleDbParameter = cmd.Parameters.Add("@Param", "<val>")
Dim dr As OleDbDataReader
dr = cmd.ExecuteReader()

Should I continue to use SystemData.OleDb for Sql Server access? Why am I
getting an error with SqlClient?

Thanks.

Mar 28 '06 #2
Thanks...that worked.

Is one better than the other? Should I use SqlClient for Sql Server?
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OK**************@tk2msftngp13.phx.gbl...
Hi,

The sqlclient class only works with sql server. You do not
need the provider in the connection string.

Ken
---------
"mrmagoo" <-> wrote in message

news:uT**************@TK2MSFTNGP12.phx.gbl...
I'm using the System.Data.OleDb for SQL Server access, and it works
perfectly. However, I see a lot of code examples that use
System.Data.SqlClient. So I try it and it and can't get it to work.

Here are my samples. Why does Oledb work and SqlClient not?

' At the top of the module:
Imports System.Data.SqlClient

Dim cn As SqlConnection = New SqlConnection("<ConnString>") '< -- error here
cn.Open()
Dim cmd As SqlCommand = New SqlCommand("MyStoredProc", cn)
cmd.CommandType = CommandType.StoredProcedure
Dim param As SqlParameter = cmd.Parameters.Add("@Param", "<val>")
Dim dr As SqlDataReader
dr = cmd.ExecuteReader()

When I run it, I get an error on the Dim cn As SqlConnection line:
--------------------------------------
An unhandled exception of type 'System.ArgumentException' occurred in
system.data.dll
Additional information: Keyword not supported: 'provider'.
--------------------------------------
But this works fine.

' At the top of the module:
Imports System.Data.OleDb

Dim cn As OleDbConnection = New OleDbConnection("<ConnString>")
cn.Open()
Dim cmd As OleDbCommand = New OleDbCommand("MyStoredProc", cn)
cmd.CommandType = CommandType.StoredProcedure
Dim param As OleDbParameter = cmd.Parameters.Add("@Param", "<val>")
Dim dr As OleDbDataReader
dr = cmd.ExecuteReader()

Should I continue to use SystemData.OleDb for Sql Server access? Why am I getting an error with SqlClient?

Thanks.


Mar 28 '06 #3
Hi,

Use sqlclient it is optimized for sql server.

Ken
------------
"mrmagoo" <-> wrote in message news:OJ**************@TK2MSFTNGP09.phx.gbl...
Thanks...that worked.

Is one better than the other? Should I use SqlClient for Sql Server?
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OK**************@tk2msftngp13.phx.gbl...
Hi,

The sqlclient class only works with sql server. You do not
need the provider in the connection string.

Ken
---------
"mrmagoo" <-> wrote in message

news:uT**************@TK2MSFTNGP12.phx.gbl...
> I'm using the System.Data.OleDb for SQL Server access, and it works
> perfectly. However, I see a lot of code examples that use
> System.Data.SqlClient. So I try it and it and can't get it to work.
>
> Here are my samples. Why does Oledb work and SqlClient not?
>
> ' At the top of the module:
> Imports System.Data.SqlClient
>
> Dim cn As SqlConnection = New SqlConnection("<ConnString>") '< -- error > here
> cn.Open()
> Dim cmd As SqlCommand = New SqlCommand("MyStoredProc", cn)
> cmd.CommandType = CommandType.StoredProcedure
> Dim param As SqlParameter = cmd.Parameters.Add("@Param", "<val>")
> Dim dr As SqlDataReader
> dr = cmd.ExecuteReader()
>
> When I run it, I get an error on the Dim cn As SqlConnection line:
> --------------------------------------
> An unhandled exception of type 'System.ArgumentException' occurred in
> system.data.dll
> Additional information: Keyword not supported: 'provider'.
> --------------------------------------
>
>
> But this works fine.
>
> ' At the top of the module:
> Imports System.Data.OleDb
>
> Dim cn As OleDbConnection = New OleDbConnection("<ConnString>")
> cn.Open()
> Dim cmd As OleDbCommand = New OleDbCommand("MyStoredProc", cn)
> cmd.CommandType = CommandType.StoredProcedure
> Dim param As OleDbParameter = cmd.Parameters.Add("@Param", "<val>")
> Dim dr As OleDbDataReader
> dr = cmd.ExecuteReader()
>
> Should I continue to use SystemData.OleDb for Sql Server access? Why am I > getting an error with SqlClient?
>
> Thanks.
>
>
>
>



Mar 28 '06 #4
thanks!

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uT**************@tk2msftngp13.phx.gbl...
Hi,

Use sqlclient it is optimized for sql server.

Ken
------------
"mrmagoo" <-> wrote in message

news:OJ**************@TK2MSFTNGP09.phx.gbl...
Thanks...that worked.

Is one better than the other? Should I use SqlClient for Sql Server?
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OK**************@tk2msftngp13.phx.gbl...
Hi,

The sqlclient class only works with sql server. You do not need the provider in the connection string.

Ken
---------
"mrmagoo" <-> wrote in message

news:uT**************@TK2MSFTNGP12.phx.gbl...
> I'm using the System.Data.OleDb for SQL Server access, and it works
> perfectly. However, I see a lot of code examples that use
> System.Data.SqlClient. So I try it and it and can't get it to work.
>
> Here are my samples. Why does Oledb work and SqlClient not?
>
> ' At the top of the module:
> Imports System.Data.SqlClient
>
> Dim cn As SqlConnection = New SqlConnection("<ConnString>") '< --

error
> here
> cn.Open()
> Dim cmd As SqlCommand = New SqlCommand("MyStoredProc", cn)
> cmd.CommandType = CommandType.StoredProcedure
> Dim param As SqlParameter = cmd.Parameters.Add("@Param", "<val>")
> Dim dr As SqlDataReader
> dr = cmd.ExecuteReader()
>
> When I run it, I get an error on the Dim cn As SqlConnection line:
> --------------------------------------
> An unhandled exception of type 'System.ArgumentException' occurred in
> system.data.dll
> Additional information: Keyword not supported: 'provider'.
> --------------------------------------
>
>
> But this works fine.
>
> ' At the top of the module:
> Imports System.Data.OleDb
>
> Dim cn As OleDbConnection = New OleDbConnection("<ConnString>")
> cn.Open()
> Dim cmd As OleDbCommand = New OleDbCommand("MyStoredProc", cn)
> cmd.CommandType = CommandType.StoredProcedure
> Dim param As OleDbParameter = cmd.Parameters.Add("@Param", "<val>")
> Dim dr As OleDbDataReader
> dr = cmd.ExecuteReader()
>
> Should I continue to use SystemData.OleDb for Sql Server access? Why
am I
> getting an error with SqlClient?
>
> Thanks.
>
>
>
>



Mar 29 '06 #5
See www.ConnectionStrings.com for a properly formed SqlConnection
ConnString.

"mrmagoo" <-> wrote in message news:uT**************@TK2MSFTNGP12.phx.gbl...
I'm using the System.Data.OleDb for SQL Server access, and it works
perfectly. However, I see a lot of code examples that use
System.Data.SqlClient. So I try it and it and can't get it to work.

Here are my samples. Why does Oledb work and SqlClient not?

' At the top of the module:
Imports System.Data.SqlClient

Dim cn As SqlConnection = New SqlConnection("<ConnString>") '< -- error
here
cn.Open()
Dim cmd As SqlCommand = New SqlCommand("MyStoredProc", cn)
cmd.CommandType = CommandType.StoredProcedure
Dim param As SqlParameter = cmd.Parameters.Add("@Param", "<val>")
Dim dr As SqlDataReader
dr = cmd.ExecuteReader()

When I run it, I get an error on the Dim cn As SqlConnection line:
--------------------------------------
An unhandled exception of type 'System.ArgumentException' occurred in
system.data.dll
Additional information: Keyword not supported: 'provider'.
--------------------------------------
But this works fine.

' At the top of the module:
Imports System.Data.OleDb

Dim cn As OleDbConnection = New OleDbConnection("<ConnString>")
cn.Open()
Dim cmd As OleDbCommand = New OleDbCommand("MyStoredProc", cn)
cmd.CommandType = CommandType.StoredProcedure
Dim param As OleDbParameter = cmd.Parameters.Add("@Param", "<val>")
Dim dr As OleDbDataReader
dr = cmd.ExecuteReader()

Should I continue to use SystemData.OleDb for Sql Server access? Why am I
getting an error with SqlClient?

Thanks.

Mar 29 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chris Thunell | last post by:
I have a program where i connect to an access database and get some information out of it. I'm using the oledb.3.51 version, my computer doesn't seem to have the 4.0 version, but the computer that...
2
by: gigi | last post by:
I have a strange problem with an OleDB call to a stored procedure that returns a rowset. Only the first time I execute the query, after I restart SqlServer, my program crashes because the rowset...
2
by: WeiminZhang | last post by:
When I use the OleDb to connect a Oracle db, and use the ExecutScalar() method to get the count of a table, the return value can't be cast to a data type, say int, while this works fine for a SQL...
1
by: mp | last post by:
Hi, I have following problem: Operation must use an updateable query I have use OleDb, C# and ASP.NET and MS Access DB named pubs. Code:
1
by: Billy Hart | last post by:
I am getting this error on my win 2000 server when a .net app that a programmer in my office developed. I have read other posts about the issue but the resolutions to those posts did not solve the...
2
by: Martin | last post by:
Hi, I currently have an application that connects to an MS ACCESS database. This application uses an OLEDB connection string for MS ACCESS. Now, I'd like to upsize the application so I converted...
5
by: petro | last post by:
Hello all, My asp.net web application works on my machine but I get the following error on our test web server, There is only one oracle home on the test server. Does anyone know how to resolve...
3
by: blue875 | last post by:
When I run this connection, I get a security error. String connectStr = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"User Id=USER; Password=PASS;" + @"Data Source=\\SERVER\DIRECTORY\Data.mdb;" +...
3
by: asemeiks | last post by:
I'm using Access 97, Jet 4.0. the data resides on a Win 2000 domain server. Using .Net 1.1 and IIS 5.0 on a local XPPro computer I am trying connect to a Jet database on the server. If the data...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.