views:

154

answers:

4

I am not sure I am getting the correct definition for what API Usage is. I have a snippet of code that is used for a BulkInsert into SQL from c# application. It said the snippet shows the API usage. How do I translate that?

private void WriteToDatabase()
{
    // get your connection string
    string connString = "";
    // connect to SQL
    using (SqlConnection connection = 
            new SqlConnection(connString))
    {
        // make sure to enable triggers
        // more on triggers in next post
        SqlBulkCopy bulkCopy = 
            new SqlBulkCopy
            (
            connection, 
            SqlBulkCopyOptions.TableLock | 
            SqlBulkCopyOptions.FireTriggers | 
            SqlBulkCopyOptions.UseInternalTransaction,
            null
            );

        // set the destination table name
        bulkCopy.DestinationTableName = this.tableName;
        connection.Open();

        // write the data in the "dataTable"
        bulkCopy.WriteToServer(dataTable);
        connection.Close();
    }
    // reset
    this.dataTable.Clear();
    this.recordCount = 0;
}
A: 

Do you mean something like "System Integration," where you are writing code that connects to an API for something? If not, you may have to elaborate a bit more in terms of context.

EDIT: It would appear to me that you are merely testing the API by giving it a simple case to process. This is using the API and I could see some cases where one wants to find all instances where a particular API call is used such as if one is changing the API.

JB King
I made the edit. Hopefully this answers your question
A: 

API just stand for Application Programming Interface. An API can be exposed by many different libraries. The question itself is fairly vague, perhaps you can post the snippet and let us know what library the API is supposed to be for and we can help you identify the parts of code that are API calls.

Edit: The lines below show the particular calls that are being made to the API.

In terms of how you translate, i'm still not exactly sure what you mean.

    SqlBulkCopy bulkCopy = 
        new SqlBulkCopy
        (
        connection, 
        SqlBulkCopyOptions.TableLock | 
        SqlBulkCopyOptions.FireTriggers | 
        SqlBulkCopyOptions.UseInternalTransaction,
        null
        );

    // set the destination table name
    bulkCopy.DestinationTableName = this.tableName;

    // write the data in the "dataTable"
    bulkCopy.WriteToServer(dataTable);
Quintin Robinson
made the edit change... hope this makes it a bit clearer.
A: 

I would assume that it is a simple snippet that records the number of times a method or set of methods is accessed, perhaps with timings. Essentially, profiling calls over a particular boundary.

An API is just the mechanism for 2 bits of code to talk. That could be a managed interface etc call, an unmanaged (interop) call, a web-request, etc. Anything that allows you to use a particular bit of functionality. Vague enough?

(edit: the question keeps changing!!) In the case of "BulkInsert into SQL from c# application", I assume it highlights usage of SqlBulkCopy and/or TSQL bulk inserts from .NET callers. For example, SqlBulkCopy has events for every batch of rows...

Marc Gravell
+3  A: 

An application programming interface (API) is a set of routines, data structures, object classes and/or protocols provided by libraries and/or operating system services in order to support the building of applications

In simpler terms, an API consists of the bits of an assembly you can see and interact with from the outsdie. The Microsoft.NET framework has LOTS of stuff that you can't use because they are not part of the framework's API. These classes, methods, interfaces, etc are marked internal or private, and are intended for use by MS.

What you're looking at is just an example of using this code from the perspective of someone on the outside of the library looking in. In other words, you could have written this code yourself, as a consumer of the API. It doesn't detail all the possible ways to use the API, but it gives you a hint.

Will