PC Review


Reply
Thread Tools Rate Thread

DbProviderFactories.GetFactory(row) exception

 
 
=?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=
Guest
Posts: n/a
 
      9th Dec 2005
Hi;

I have the following code:
DataTable table = DbProviderFactories.GetFactoryClasses();
foreach (DataRow row in DbProviderFactories.GetFactoryClasses().Rows)
DbProviderFactory providerFactory = DbProviderFactories.GetFactory(row);

The DbProviderFactories.GetFactory(row) throws an exception when the row has
the values: "SQL Server CE Data Provider", ".NET Framework Data Provider for
Microsoft SQL Server 2005 Mobile Edition", "Microsoft.SqlServerCe.Client",
"Microsoft.SqlServerCe.Client.SqlCeClientFactory,
Microsoft.SqlServerCe.Client, Version=9.0.242.0, Culture=neutral,
PublicKeyToken=89845dcd8080cc91"

The exception is:
System.Configuration.ConfigurationErrorsException was unhandled
Message="Failed to find or load the registered .Net Framework Data
Provider."
Source="System.Data"
BareMessage="Failed to find or load the registered .Net Framework Data
Provider."
Line=0
StackTrace:
at System.Data.Common.DbProviderFactories.GetFactory(DataRow
providerRow)
at DbTest.Program.Main(String[] args) in
c:\src\MyWordAddin\DbTest\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()


What is going on?

--
thanks - dave
 
Reply With Quote
 
 
 
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      9th Dec 2005
Hi dave,

Based on my research, the Microsoft.SqlServerCe.Client assembly is
installed with SQL Server 2005 and VS.NET 2005. However, it was not
registered to the GAC. The assembly is at C:\Program Files\Microsoft Visual
Studio 8\Common7\IDE\Microsoft.SqlServerCe.Client.dll. You can add this to
GAC, so your code will run fine.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

 
Reply With Quote
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      9th Dec 2005
Also Microsoft.SqlServerCe.Client.dll is not supported and hence not
documented. You can check the following link for more information.

http://forums.microsoft.com/MSDN/Sho...24762&SiteID=1

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

 
Reply With Quote
 
=?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=
Guest
Posts: n/a
 
      9th Dec 2005
Hello;

My concern is this call throwing an exception on user's systems. And I can't
tell them all to fix how the Sql Server CE client was installed. How can I
determine if I can call GetFactory() for a given row?

I don't want to have a try/catch because I think it is very poor programming
practice to have exceptions thrown &and caught) when the program is operating
normally.

--
thanks - dave


"Kevin Yu [MSFT]" wrote:

> Hi dave,
>
> Based on my research, the Microsoft.SqlServerCe.Client assembly is
> installed with SQL Server 2005 and VS.NET 2005. However, it was not
> registered to the GAC. The assembly is at C:\Program Files\Microsoft Visual
> Studio 8\Common7\IDE\Microsoft.SqlServerCe.Client.dll. You can add this to
> GAC, so your code will run fine.
>
> HTH.
>
> Kevin Yu
> =======
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
>
>

 
Reply With Quote
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      10th Dec 2005
You can check the content of the rows and skip Microsoft.SqlServerCe.Client.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

 
Reply With Quote
 
=?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=
Guest
Posts: n/a
 
      10th Dec 2005
Hi;

I don't think that is a good solution. If they have Ce.Client installed,
then I don't want to skip it.

And what if they have another client that throws an exception?

I want to know how to avoid calling this methid fi, and only if, it will
throw an exception.

--
thanks - dave


"Kevin Yu [MSFT]" wrote:

> You can check the content of the rows and skip Microsoft.SqlServerCe.Client.
>
> Kevin Yu
> =======
> "This posting is provided "AS IS" with no warranties, and confers no
> rights."
>
>

 
Reply With Quote
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      13th Dec 2005
Hi dave,

The information is located in the machine.config file under
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG folder. Here is an
example.

<system.data>
<DbProviderFactories>
<add name="Odbc Data Provider" invariant="System.Data.Odbc"
description=".Net Framework Data Provider for Odbc"
type="System.Data.Odbc.OdbcFactory, System.Data, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add name="OleDb Data Provider" invariant="System.Data.OleDb"
description=".Net Framework Data Provider for OleDb"
type="System.Data.OleDb.OleDbFactory, System.Data, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add name="OracleClient Data Provider"
invariant="System.Data.OracleClient" description=".Net Framework Data
Provider for Oracle" type="System.Data.OracleClient.OracleClientFactory,
System.Data.OracleClient, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" />
<add name="SqlClient Data Provider" invariant="System.Data.SqlClient"
description=".Net Framework Data Provider for SqlServer"
type="System.Data.SqlClient.SqlClientFactory, System.Data, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add name="SQL Server CE Data Provider"
invariant="Microsoft.SqlServerCe.Client" description=".NET Framework Data
Provider for Microsoft SQL Server 2005 Mobile Edition"
type="Microsoft.SqlServerCe.Client.SqlCeClientFactory,
Microsoft.SqlServerCe.Client, Version=9.0.242.0, Culture=neutral,
PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>
</system.data>

If other provider need themselves to be enumerated, they need to

1. add themselves to the GAC,
2. add a new node in the machine.config file.

Currently, they best way to workaround this is to use try/catch block. I
don't have other better ways.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sybase AsaClient and DbProviderFactories JC Microsoft ADO .NET 0 23rd Oct 2007 03:20 AM
DbProviderFactories and multiple versions of connector FAILS Jeff Jarrell Microsoft ADO .NET 0 12th Oct 2007 06:20 PM
machine.config and DbProviderFactories + gacutil registration =?Utf-8?B?eG9yX2VheF9lYXg=?= Microsoft ADO .NET 0 7th Aug 2006 04:38 PM
DbProvider GetFactory exception with system.data.sqlclient =?Utf-8?B?bGs=?= Microsoft ADO .NET 2 14th Mar 2006 02:00 PM
DbProviderFactory & creating from DbProviderFactories.GetFactoryCl =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= Microsoft ADO .NET 3 10th Mar 2006 05:49 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:04 AM.