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

    To create a connection to a ServiceNow data source, the ADO.NET Provider can be used through the C1ServiceNowConnection class. This expects to be passed a connection string as an argument, which can be either:

    Connection string generation

    The following code shows how C1ServiceNowConnectionStringBuilder class can be used to configure the connection string for ServiceNow and consumed by the C1ServiceNowConnection class to create a connection to the server. Here, you can query the data.

    C#
    Copy Code
    //Create connection string using C1ServiceNowConnectionStringBuilder
    connBuilder.Username = @"*******";
    connBuilder.Password = @"*******";
    connBuilder.OAuthClientId = @"*******";
    connBuilder.OAuthClientSecret = @"*******";
    connBuilder.OAuthTokenEndpoint = @"http://****/****/****";
    connBuilder.Url = @"http://****/****/****";
    
    //Create and establish a connection
    C1ServiceNowConnection conn = new C1ServiceNowConnection(connBuilder)

    Connection string literal

    Alternatively, the connection string can be written directly as a string literal like in the code example below. A similar approach can be implemented in other DataConnectors for ADO.NET provider.

    C#
    Copy Code
    //Define connection string
    string connectionString = @"Username= *******; Password= *******; Oauth Client Id= *******; 
    Oauth Client Secret= *******; Oauth Token Endpoint= http://****/****/****; Url= http://****/****/****";
    //Create and establish a connection
    C1ServiceNowConnection conn = new C1ServiceNowConnection(connectionString);