473,657 Members | 2,504 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

I'm using the System.Data.Ole Db for SQL Server access, and it works
perfectly. However, I see a lot of code examples that use
System.Data.Sql Client. 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.Sql Client

Dim cn As SqlConnection = New SqlConnection(" <ConnString>" ) '< -- error
here
cn.Open()
Dim cmd As SqlCommand = New SqlCommand("MyS toredProc", cn)
cmd.CommandType = CommandType.Sto redProcedure
Dim param As SqlParameter = cmd.Parameters. Add("@Param", "<val>")
Dim dr As SqlDataReader
dr = cmd.ExecuteRead er()

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

' At the top of the module:
Imports System.Data.Ole Db

Dim cn As OleDbConnection = New OleDbConnection ("<ConnString>" )
cn.Open()
Dim cmd As OleDbCommand = New OleDbCommand("M yStoredProc", cn)
cmd.CommandType = CommandType.Sto redProcedure
Dim param As OleDbParameter = cmd.Parameters. Add("@Param", "<val>")
Dim dr As OleDbDataReader
dr = cmd.ExecuteRead er()

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

Thanks.


Mar 28 '06 #1
5 1660
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******** ******@TK2MSFTN GP12.phx.gbl...
I'm using the System.Data.Ole Db for SQL Server access, and it works
perfectly. However, I see a lot of code examples that use
System.Data.Sql Client. 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.Sql Client

Dim cn As SqlConnection = New SqlConnection(" <ConnString>" ) '< -- error
here
cn.Open()
Dim cmd As SqlCommand = New SqlCommand("MyS toredProc", cn)
cmd.CommandType = CommandType.Sto redProcedure
Dim param As SqlParameter = cmd.Parameters. Add("@Param", "<val>")
Dim dr As SqlDataReader
dr = cmd.ExecuteRead er()

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

' At the top of the module:
Imports System.Data.Ole Db

Dim cn As OleDbConnection = New OleDbConnection ("<ConnString>" )
cn.Open()
Dim cmd As OleDbCommand = New OleDbCommand("M yStoredProc", cn)
cmd.CommandType = CommandType.Sto redProcedure
Dim param As OleDbParameter = cmd.Parameters. Add("@Param", "<val>")
Dim dr As OleDbDataReader
dr = cmd.ExecuteRead er()

Should I continue to use SystemData.OleD b 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***@bellsout h.net> wrote in message
news:OK******** ******@tk2msftn gp13.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******** ******@TK2MSFTN GP12.phx.gbl...
I'm using the System.Data.Ole Db for SQL Server access, and it works
perfectly. However, I see a lot of code examples that use
System.Data.Sql Client. 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.Sql Client

Dim cn As SqlConnection = New SqlConnection(" <ConnString>" ) '< -- error here
cn.Open()
Dim cmd As SqlCommand = New SqlCommand("MyS toredProc", cn)
cmd.CommandType = CommandType.Sto redProcedure
Dim param As SqlParameter = cmd.Parameters. Add("@Param", "<val>")
Dim dr As SqlDataReader
dr = cmd.ExecuteRead er()

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

' At the top of the module:
Imports System.Data.Ole Db

Dim cn As OleDbConnection = New OleDbConnection ("<ConnString>" )
cn.Open()
Dim cmd As OleDbCommand = New OleDbCommand("M yStoredProc", cn)
cmd.CommandType = CommandType.Sto redProcedure
Dim param As OleDbParameter = cmd.Parameters. Add("@Param", "<val>")
Dim dr As OleDbDataReader
dr = cmd.ExecuteRead er()

Should I continue to use SystemData.OleD b 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******** ******@TK2MSFTN GP09.phx.gbl...
Thanks...that worked.

Is one better than the other? Should I use SqlClient for Sql Server?
"Ken Tucker [MVP]" <vb***@bellsout h.net> wrote in message
news:OK******** ******@tk2msftn gp13.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******** ******@TK2MSFTN GP12.phx.gbl...
> I'm using the System.Data.Ole Db for SQL Server access, and it works
> perfectly. However, I see a lot of code examples that use
> System.Data.Sql Client. 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.Sql Client
>
> Dim cn As SqlConnection = New SqlConnection(" <ConnString>" ) '< -- error > here
> cn.Open()
> Dim cmd As SqlCommand = New SqlCommand("MyS toredProc", cn)
> cmd.CommandType = CommandType.Sto redProcedure
> Dim param As SqlParameter = cmd.Parameters. Add("@Param", "<val>")
> Dim dr As SqlDataReader
> dr = cmd.ExecuteRead er()
>
> When I run it, I get an error on the Dim cn As SqlConnection line:
> --------------------------------------
> An unhandled exception of type 'System.Argumen tException' occurred in
> system.data.dll
> Additional information: Keyword not supported: 'provider'.
> --------------------------------------
>
>
> But this works fine.
>
> ' At the top of the module:
> Imports System.Data.Ole Db
>
> Dim cn As OleDbConnection = New OleDbConnection ("<ConnString>" )
> cn.Open()
> Dim cmd As OleDbCommand = New OleDbCommand("M yStoredProc", cn)
> cmd.CommandType = CommandType.Sto redProcedure
> Dim param As OleDbParameter = cmd.Parameters. Add("@Param", "<val>")
> Dim dr As OleDbDataReader
> dr = cmd.ExecuteRead er()
>
> Should I continue to use SystemData.OleD b for Sql Server access? Why am I > getting an error with SqlClient?
>
> Thanks.
>
>
>
>



Mar 28 '06 #4
thanks!

"Ken Tucker [MVP]" <vb***@bellsout h.net> wrote in message
news:uT******** ******@tk2msftn gp13.phx.gbl...
Hi,

Use sqlclient it is optimized for sql server.

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

news:OJ******** ******@TK2MSFTN GP09.phx.gbl...
Thanks...that worked.

Is one better than the other? Should I use SqlClient for Sql Server?
"Ken Tucker [MVP]" <vb***@bellsout h.net> wrote in message
news:OK******** ******@tk2msftn gp13.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******** ******@TK2MSFTN GP12.phx.gbl...
> I'm using the System.Data.Ole Db for SQL Server access, and it works
> perfectly. However, I see a lot of code examples that use
> System.Data.Sql Client. 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.Sql Client
>
> Dim cn As SqlConnection = New SqlConnection(" <ConnString>" ) '< --

error
> here
> cn.Open()
> Dim cmd As SqlCommand = New SqlCommand("MyS toredProc", cn)
> cmd.CommandType = CommandType.Sto redProcedure
> Dim param As SqlParameter = cmd.Parameters. Add("@Param", "<val>")
> Dim dr As SqlDataReader
> dr = cmd.ExecuteRead er()
>
> When I run it, I get an error on the Dim cn As SqlConnection line:
> --------------------------------------
> An unhandled exception of type 'System.Argumen tException' occurred in
> system.data.dll
> Additional information: Keyword not supported: 'provider'.
> --------------------------------------
>
>
> But this works fine.
>
> ' At the top of the module:
> Imports System.Data.Ole Db
>
> Dim cn As OleDbConnection = New OleDbConnection ("<ConnString>" )
> cn.Open()
> Dim cmd As OleDbCommand = New OleDbCommand("M yStoredProc", cn)
> cmd.CommandType = CommandType.Sto redProcedure
> Dim param As OleDbParameter = cmd.Parameters. Add("@Param", "<val>")
> Dim dr As OleDbDataReader
> dr = cmd.ExecuteRead er()
>
> Should I continue to use SystemData.OleD b 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******** ******@TK2MSFTN GP12.phx.gbl...
I'm using the System.Data.Ole Db for SQL Server access, and it works
perfectly. However, I see a lot of code examples that use
System.Data.Sql Client. 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.Sql Client

Dim cn As SqlConnection = New SqlConnection(" <ConnString>" ) '< -- error
here
cn.Open()
Dim cmd As SqlCommand = New SqlCommand("MyS toredProc", cn)
cmd.CommandType = CommandType.Sto redProcedure
Dim param As SqlParameter = cmd.Parameters. Add("@Param", "<val>")
Dim dr As SqlDataReader
dr = cmd.ExecuteRead er()

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

' At the top of the module:
Imports System.Data.Ole Db

Dim cn As OleDbConnection = New OleDbConnection ("<ConnString>" )
cn.Open()
Dim cmd As OleDbCommand = New OleDbCommand("M yStoredProc", cn)
cmd.CommandType = CommandType.Sto redProcedure
Dim param As OleDbParameter = cmd.Parameters. Add("@Param", "<val>")
Dim dr As OleDbDataReader
dr = cmd.ExecuteRead er()

Should I continue to use SystemData.OleD b 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
1847
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 is trying to run it only have the 4.0 version. So as you will see with the code below, i first try to open the 4.0 version... if that doesn't work, do the 3.51 version. When i run the program from my computer... the 4.0 fails and it goes to...
2
2619
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 is empty. All next calls (after restarting my program, of course) run successfully. The context is: 1) if I do not bind the output rowset, my program doesn't crash 2) If I run the call without the binding and then I run the call with
2
13016
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 server db using SqlCommand. Following is the code example: string strCnt = "SELECT count (*) from B_PlanSchemeItems"; string strSource="Provider=MSDAORA;Data Source=avocet1;User ID=dbo; Password=mmsmms;";
1
321
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
662
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 problem. I know that when you install .net it is supposed to create a directory under documents and settings with the name of the server in my case it should be "\documents and settings\arete1\aspnet\local settings\temp" this was not created in several...
2
2849
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 the db to SQL SERVER and this went well. Next thing I changed the connection string from OLEDB for MS ACCESS to OLEDB for SQL SERVER. I expected this to work resonably well, however I found that it never worked
5
9641
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 this error? Oracle error occurred, but error message could not be retrieved from Oracle. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the...
3
9146
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;" + @"Jet OLEDB:System Database=\\SERVER\DIRECTORY\SYSTEM.mdw"; connection = new OleDbConnection(connectStr); connection.Open(); // <=== error!
3
4264
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 source is on the local computer I can connect ok. If it is is on the server I cannot connect and get the following error. 'Error message. "The Microsoft Jet database engine cannot open the file ''. It is already opened exclusively by another...
0
8823
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8726
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7320
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1944
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1604
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.