1

I am trying to use multi thread for connecting CData drivers. Whether is it possible for parallel processing of data in CData.

OdbcConnection conn = new OdbcConnection();
conn.ConnectionString = "xxxx";
Task task1 = Task.Factory.StartNew(() => ReadData(conn));
Task task2 = Task.Factory.StartNew(() => ReadData(conn));
Task task3 = Task.Factory.StartNew(() => ReadData(conn));
Task task4 = Task.Factory.StartNew(() => ReadData(conn));
Task task5 = Task.Factory.StartNew(() => ReadData(conn));
public static void ReadData(OdbcConnection con)
        {
                con.Open();
                // code
         }

Please let me know it there is any solution. Thanks in advance.

Saqib Ali
  • 3,953
  • 10
  • 55
  • 100
mRhNs13
  • 479
  • 5
  • 25
  • Have you tried this? Are you seeing any error messages or unexpected behavior? If so, please provide the error message or describe the unexpected behavior. – Jerod Johnson Jan 25 '18 at 14:10
  • Yes I have tried this code and facing the issue as follows: A registration already exists for the URI "'http://localhost:7485/'". The port gets started for the first thread and throws exception for the next threads. – mRhNs13 Jan 25 '18 at 16:53
  • Can you clarify which CData Driver you're using? Different drivers have different requirements for OAuth, depending on the Data Source (Salesforce, QuickBooks, Google BigQuery, etc.). – Jerod Johnson Jan 25 '18 at 17:10
  • I am trying this for Cdata Quickbooks and Google analytics data sources. For both drivers I am facing the same issue for Oauth authentication. – mRhNs13 Jan 26 '18 at 05:40
  • Hi Jerod, I have tried your solution but i dont have such folder in my machine. My path is: "C:\Users\xxx\AppData\Roaming\CData" I dont have driver folder. I tried by uninstalling and reinstalling cdata Google analytics driver. still i don't find any driver folder in this path as you have mentioned. – mRhNs13 Jan 29 '18 at 07:38
  • You can simply create that folder, or point the driver to use another, already existing location that you have read/write permissions for. – Jerod Johnson Jan 29 '18 at 14:01
  • After trying this I am facing this issue: "The driver requires a user prompt for OAuth authentication which is not allowed by this application. Please use the DSN manager to authenticate before using the driver in this application." Please let me know how to proceed with this.? Thanks in advance. – mRhNs13 Jan 30 '18 at 11:38
  • I've updated my answer. – Jerod Johnson Jan 30 '18 at 14:40

1 Answers1

0

This is possible. If you set the OAuthSettingsLocation property using the Other property, you can perform parallel processing of data. You can set the property in the DSN or dynamically in a DSN-less connection (see the code sample below).

OAuthSettingsLocation - The location of the settings file where OAuth values are saved. This can be any location on disk for which the driver has read/write permissions.

Performing OAuth Using the DSN Manager

You will need to authenticate with the service before using the driver. To do so, you can use the Test Connection in the DSN Wizard.

  1. Open the ODBC Data Source Administrator (from the Start Menu, type "ODBC")
  2. Select or create a new DSN using the driver.
  3. Set the OAuthSettingsLocation property in the Other property and click Test Connection. (You will be prompted to authenticate with the service in a new browser window.)

Code Sample

string driver = "CData ODBC Driver for QuickBooksOnline";
string oauthSettingsLocation = "C:/users//AppData/Roaming/CData/QuickBooksOnline ODBC Driver";
string connString = "DRIVER={" + driver + "};Other=OAuthSettingsLocation=" + oauthSettingsLocation;
Task task1 = Task.Factory.StartNew(() => ReadData(new OdbcConnection(connString)));
Task task2 = Task.Factory.StartNew(() => ReadData(new OdbcConnection(connString)));
Task task3 = Task.Factory.StartNew(() => ReadData(new OdbcConnection(connString)));
Task task4 = Task.Factory.StartNew(() => ReadData(new OdbcConnection(connString)));
Task task5 = Task.Factory.StartNew(() => ReadData(new OdbcConnection(connString)));

NOTE

CData Software also makes ADO.NET Providers that might provide a more native experience in .NET applications.

Jerod Johnson
  • 764
  • 7
  • 15