I would like to create a datacontext with a specified Dbconnection, means a connection has already been created before. But i found that i was asked to provide a DataProvider through the DataProviderAttribute.
Why is this mandatory? If so, does that mean the datacontext internal will not alwasy use my connection but will use the DataProvider to create a new one?
Why DataProvider is mandatory
Re: Why DataProvider is mandatory
The point is that the Devart.Data.Linq.DataContext class can use different data providers to connect to different DBMSs. Thus, when a DataContext instance is created, it should know which data provider to use. You can specify this data provider, e.g., by setting the ProviderAttribute class attribute for YourDataContext.
In case, when the connection is passed to the DataContext constructor, exactly this connection will be used. For example:For more information please refer to:
http://www.devart.com/linqconnect/docs/ ... ntext.html
http://www.devart.com/linqconnect/docs/ ... _ctor.html
Also, please pay attention to the MaxUsedConnections property, which gets or sets the maximal number of opened connections.
In case, when the connection is passed to the DataContext constructor, exactly this connection will be used. For example:
Code: Select all
Devart.Data.Oracle.OracleConnection connection = new Devart.Data.Oracle.OracleConnection(connectionString);
YourDataContext context = new YourDataContext(connection);
http://www.devart.com/linqconnect/docs/ ... ntext.html
http://www.devart.com/linqconnect/docs/ ... _ctor.html
Also, please pay attention to the MaxUsedConnections property, which gets or sets the maximal number of opened connections.
Re: Why DataProvider is mandatory
Are you suggesting the dataconnection is still not enought for the datacontext, some other properties or methods are still required thought the dataprovider in order to make the datacontext work properly.
Re: Why DataProvider is mandatory
You are right, DataContext cannot determine the DBMS it should work with based on the connection only, and needs a data provider description.
If you are encountering any difficulties with it, please specify them.
Feel free to contact us.
If you are encountering any difficulties with it, please specify them.
Feel free to contact us.
Re: Why DataProvider is mandatory
ok, Let me ask my specific question.
I would like to wrap the oracleconnect with my own connection to replace the oralcecommand, and then insert some profiler codes before and after the oraclecommand.executequery or nonquery methods.
for example, i would like to use my connection called ProfiledOracleConnection(OracleConnection con)
However, due to some reason, I cannot use dbProviderFactory, since i want to keep using one connection i created at beginning.
Then i met the issue, the DataProvider.Initial method will expect the connection to be type OracleConnection, since i use a OracleDataProvider.
Even after i created my own DataProvider and override the CreateConnection method, i found another issue saying the codes cannot explicit convert ProfiledOracleConnection to OracleConnection.
I even tried to let ProfiledOracleConnection inherit from OracleConnection, some issues came in saying that the connection is not opened.
Could you help me find a way to replace the OracleCommand with my implementation which just insert several profile codes, and be able to stick to using one connection?
I know DBMonitor can help on profile, however that's still not meet my requirement.
I would like to wrap the oracleconnect with my own connection to replace the oralcecommand, and then insert some profiler codes before and after the oraclecommand.executequery or nonquery methods.
for example, i would like to use my connection called ProfiledOracleConnection(OracleConnection con)
However, due to some reason, I cannot use dbProviderFactory, since i want to keep using one connection i created at beginning.
Then i met the issue, the DataProvider.Initial method will expect the connection to be type OracleConnection, since i use a OracleDataProvider.
Even after i created my own DataProvider and override the CreateConnection method, i found another issue saying the codes cannot explicit convert ProfiledOracleConnection to OracleConnection.
I even tried to let ProfiledOracleConnection inherit from OracleConnection, some issues came in saying that the connection is not opened.
Could you help me find a way to replace the OracleCommand with my implementation which just insert several profile codes, and be able to stick to using one connection?
I know DBMonitor can help on profile, however that's still not meet my requirement.
Re: Why DataProvider is mandatory
The DataProvider class checks the type of the connection passed to the context constructor. To avoid this, you can create child classes that are inherited from the OracleDataProvider and OracleConnection classes. Make sure that the ProviderAttribute of your DataContext class is set to the OracleDataProvider descendant.
We are sending you a sample project to the e-mail address you provided in your forum profile, please test it and tell us if this helps.
We are sending you a sample project to the e-mail address you provided in your forum profile, please test it and tell us if this helps.
Re: Why DataProvider is mandatory
Thanks very much. i already figured this out. You are right, beside this i also implement a custom dbproviderfactory and register it in the MyOracleProvider throught the provideName property.