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:
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.
C# |
Copy Code |
---|---|
const string Username = "*************"; const string Password = "*************"; const string Url = "https://xg0w2.kintone.com"; //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...."); Console.ReadKey(); } |
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:
C# |
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.
C# |
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."