Page 1 of 1

Use existing Connection object in DataContext

Posted: Wed 19 Feb 2014 20:27
by MiB1980
My application needs to use a security dll. The security dll returns an OracleClient.OracleConnection object. I need to use this Connection object in my application. How do I make the DataContext use my Connection object?

Re: Use existing Connection object in DataContext

Posted: Thu 20 Feb 2014 12:53
by MariiaI
The necessary connection (IDbConnection) could be passed to the DataContext constructor:
http://www.devart.com/linqconnect/docs/ ... _ctor.html
In this case a new instance of the DataContext class is initialized by referencing the connection used by the .NET Framework.

Re: Use existing Connection object in DataContext

Posted: Thu 20 Feb 2014 14:56
by MiB1980
I tried using the constructor of the DataContext as below:

<ProviderAttribute(GetType(Devart.Data.Oracle.Linq.Provider.OracleDataProvider))> _
Partial Public Class DataContext
Inherits Devart.Data.Linq.DataContext

Public Sub New()
MyBase.New(GetConnection(), GetMappingSource())
OnCreated()
End Sub

Private Shared Function GetConnection() As System.Data.IDbConnection
'Function has code to get the connection (OracleClient.OracleConnection object)
End Function
End Class

I get the following error in the call to MyBase.New:
A first chance exception of type 'System.ArgumentException' occurred in Devart.Data.Linq.dll
<Message>Invalid connection type. Expected Type: System.Data.OracleClient.OracleConnection, Actual Type: Devart.Data.Oracle.OracleConnection</Message>
<StackTrace> at Devart.Data.Linq.Provider.DataProvider.Initialize(Object connection)
at Devart.Data.Oracle.Linq.Provider.OracleDataProvider.Initialize(Object connection)
at Devart.Data.Linq.Provider.DataProvider.Devart.Data.Linq.Provider.IProvider.Initialize(IDataServices dataServices, Object connection)
at Devart.Data.Linq.DataContext.a(Object A_0, MappingSource A_1, Type A_2)
at Devart.Data.Linq.DataContext..ctor(IDbConnection connection, MappingSource mapping)

I am using the OracleDataProvider as the provider. Is this correct. Do I need to write a custom provider? Any other suggestions?

Re: Use existing Connection object in DataContext

Posted: Fri 21 Feb 2014 13:43
by MariiaI
I am using the OracleDataProvider as the provider. Is this correct. Do I need to write a custom provider? Any other suggestions?
Yes, to use a third-party data provider you need to write your custom data provider, which is inherited from the Devart.Data.Oracle.Linq.Provider.OracleDataProvider class.
JIC: We recommend you to use dotConnect for Oracle as a data provider when working with LinqConnect and Oracle. LinqConnect Professional Edition includes the Express editions of our data providers (dotConnect for Oracle bundled with LinqConnect provides basic connectivity features) and supports the corresponding databases. Please refer to: http://www.devart.com/linqconnect/editions.html

Re: Use existing Connection object in DataContext

Posted: Fri 21 Feb 2014 17:24
by MiB1980
Is there any example of a custom provider inheriting from OracleDataProvider?

Re: Use existing Connection object in DataContext

Posted: Mon 24 Feb 2014 16:06
by MariiaI
We are sending you a test project to the e-mail address you have provided in your forum profile, that demonstrates the way to implement a custom data provider. Please check that the letter is not blocked by your mail filter.

Please tell us about the results.