System.Data and System.Data.SqlClient - Which one should I use ?

S

Steven Wilmot

I've recently started to convert an old VS2003 project that was using some
SQL2000

I now want to convert this project to VS2005

I've currently referenced:
D:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll
(Version = 2.0.0.0)
AND:
D:\Program Files\Microsoft Visual Studio
8\Common7\IDE\PublicAssemblies\System.Data.SqlClient.dll (Version =
3.0.3600.0)

The question is: which one should I be using, and why does System.Data ALSO
contain a definition for SQLConnection

(Currently I get an error in my project):

An assembly with the same identity 'System.Data.SqlClient,
Version=3.0.3600.0, Culture=neutral, PublicKeyToken=3be235df1c8d2ad3,
Retargetable=Yes' has already been imported. Try removing one of the
duplicate references.
 
S

S.M. Altaf [MVP]

Simply put, System.Data is a generalized namespace for the most common
classes like DataSets, DataReaders, etc. System.Data.SqlClient is the
namespace you'd use when working with SQL Server, specifically. There are
other namespaces like System.Data.OdbcClient and OledbClient which are for
other databases.

HTH
-Altaf
 
S

Steven Wilmot

S.M. Altaf said:
Simply put, System.Data is a generalized namespace for the most common
classes like DataSets, DataReaders, etc. System.Data.SqlClient is the
namespace you'd use when working with SQL Server, specifically. There are
other namespaces like System.Data.OdbcClient and OledbClient which are for
other databases.

HTH
-Altaf

Unfortunately, this completely misses the point of my question.

I realise what the different namespaces are fo - I am asking about the two
assemblies

D:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll
This contains the namespace System.Data
This also contains the namespace System.Data.SqlClient

D:\Program Files\Microsoft Visual Studio
8\Common7\IDE\PublicAssemblies\System.Data.SqlClient.dll
This also contains the namespace System.Data.SqlClient
... But, this depends on the definition of the type
'System.Data.IDbConnection' , which is defined in an assembly that is not
referenced.:
( 'System.Data, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=969db8053d3322ac)

However, if I then add the System.Data.Dll assembly, I am presented with
another error.

An assembly with the same identity 'System.Data.SqlClient,
Version=3.0.3600.0, Culture=neutral, PublicKeyToken=3be235df1c8d2ad3,
Retargetable=Yes' has already been imported. Try removing one of the
duplicate references. d:\Program Files\Microsoft Visual Studio
8\Common7\IDE\PublicAssemblies\System.Data.SqlClient.dll WindowsApplication2
 
S

Steven Wilmot

Steven Wilmot said:
Unfortunately, this completely misses the point of my question.

I realise what the different namespaces are fo - I am asking about the two
assemblies

D:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll
This contains the namespace System.Data
This also contains the namespace System.Data.SqlClient

D:\Program Files\Microsoft Visual Studio
8\Common7\IDE\PublicAssemblies\System.Data.SqlClient.dll
This also contains the namespace System.Data.SqlClient
... But, this depends on the definition of the type
'System.Data.IDbConnection' , which is defined in an assembly that is not
referenced.:
( 'System.Data, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=969db8053d3322ac)

However, if I then add the System.Data.Dll assembly, I am presented with
another error.

An assembly with the same identity 'System.Data.SqlClient,
Version=3.0.3600.0, Culture=neutral, PublicKeyToken=3be235df1c8d2ad3,
Retargetable=Yes' has already been imported. Try removing one of the
duplicate references. d:\Program Files\Microsoft Visual Studio
8\Common7\IDE\PublicAssemblies\System.Data.SqlClient.dll
WindowsApplication2

For example:
Try referencing both assemblies, then create a simple C# project with the
following two lines of code:

System.Data.SqlClient.SqlConnection a = new
System.Data.SqlClient.SqlConnection();

MessageBox.Show(a.State.ToString());
 
G

Greg Burns

You should only reference
D:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll

(This is the one referenced by default in both C# and VB)

It contains both System.Data and System.Data.SqlClient namespaces.

I am not sure what the other one is used for (or why it has some similar
classnames), but you definately don't want to be referencing it. Maybe it an
assembly specifically written for use by the IDE? Confusing, isn't it? :^)

Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top