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

    To create a connection in ADO.NET Provider, you can use C1KintoneConnection class which implements a connection string passed as an argument. Another way to connect with the data source is using the C1KintoneConnectionStringBuilder class which builds and parses connection strings through program code.

    The C1KintoneConnectionStringBuilder class can also be used to setup the connection strings to be implemented by the provider for connecting to the datasource.

    Below code example shows how C1KintoneConnectionStringBuilder class can be used to configure the connection string for Kintone and consumed by C1KintoneConnection class to create a connection to Kintone server. You can query the data or request for modifications.

    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....");

    In C1KintoneConnectionStringBuilder class, there is a special attribute "Guest Space Id" which lets the users define tables with same names as each table will belong to its own Space. When accessing duplicate name tables, the user should access the table using App Id that represents the table's unique identity.

    App is considered as table where Apps can have duplicated names if they are in different spaces. For example, consider the followig 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)

    In case, we connect to Kintone without specifying Guest Space Id, the query Select * from Orders will throw exception because table [Orders] exists in multiple spaces. In this case, we can use following alternative queries.

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

    In another scenario, the table name should be accompanied by the GuestSpaceId. If we connect to Kintone with "Guest Space Id = 2", then only the apps of Guest Space are loaded. So 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".