DataConnector | ComponentOne
ADO.NET provider for Kintone / Creating Connection
In This Topic
    Creating Connection
    In This Topic

    To create a connection to a Kintone data source, the ADO.NET Provider can be used through the C1KintoneConnection class. This class requires a connection string to be provided as an argument, which can be created in either of the following ways:

    Connection string generation

    The following code shows how to use the C1KintoneConnectionStringBuilder class to configure the connection string for Kintone, which can then be consumed by the C1KintoneConnection class to establish a connection to the Kintone server. Through that connection, the data source can be queried, updated, etc.

    Copy Code
        const string Username = "*************";
        const string Password = "*************";
        const string Url = "";
        //Configure connection string
        C1KintoneConnectionStringBuilder builder = new C1KintoneConnectionStringBuilder();
        builder.Username = Username;
        builder.Password = Password;
        builder.Url = Url;
        //Setup Connection 
        C1KintoneConnection conn = new C1KintoneConnection(builder);
        //Optional: Just for display            
        Console.WriteLine("Connection Created with the following Connection String \n " + builder.ConnectionString);
        Console.WriteLine("\n Press any key to exit....");

    The C1KintoneConnectionStringBuilder class includes a special attribute called 'Guest Space Id', which allows users to define tables with the same name since each table will belong to its own space.

    However, when accessing duplicate tables, it is important to use the App ID, which represents the table's unique identity. In Kintone, an 'App' can be considered as a table, where duplicate names can exist if they are in different spaces. For example, consider the following Kintone account settings:

    Copy Code
    Space: Id=1, name=jcj
    App: Invoices (appid = 1)
    App: Orders (appid = 2)
    Space: Id=2, name=Guest
    App: Orders (appid = 3)

    If a connection to Kintone is established without specifying the Guest Space ID, the query 'SELECT * FROM Orders' may not work properly as the table 'Orders' may exist in multiple spaces, leading to an exception being thrown. In this situation, alternative queries that specify the App ID can be used to access the desired table as in the following example.

    Copy Code
    Select * from [3] (with "3" is id of app Orders)
    Select * from Guest.Orders

    If the connection to Kintone is established with the parameter 'Guest Space Id = 2', only the apps of the specified Guest Space are loaded. In this scenario, the table name should be accompanied by the Guest Space Id to ensure that the correct table is accessed. Therefore, the query 'SELECT * FROM Orders' can be used."

    Note: The properties of C1KintoneConnectionStringBuilder can be used to setup the connection keys when passed as connection strings. The connection key will be the corresponding property with added space character. For example, "UseCache" will be used as "Use Cache".