Standard ADO.NET Access to Cosmos DB
The Cosmos DB ADO.NET Provider offers the most natural way to access Cosmos DB data from any
.NET application. Simply use Cosmos DB Data Provider objects to connect and access data just as you
would access any traditional database. You will be able to use the Cosmos DB Data Provider through
Visual Studio Server Explorer, in code through familiar classes, and in data controls like DataGridView, GridView,
DataSet, etc.
The CData ADO.NET Provider for Cosmos DB hides the complexity of accessing data and provides additional powerful security features,
smart caching, batching, socket management, and more.
Working with DataAdapters, DataSets, DataTables, etc.
The Cosmos DB Data Provider has the same ADO.NET architecture as the native .NET data providers for SQL Server
and OLEDB, including: Cosmos DBConnection, Cosmos DBCommand, Cosmos DBDataAdapter, Cosmos DBDataReader,
Cosmos DBDataSource, Cosmos DBParameter, etc. Because of
this you can now access Cosmos DB data in an easy, familiar way.
For example:
using (Cosmos DBConnection conn = new Cosmos DBConnection("...")) {
string select = "SELECT * FROM DocumentDB";
Cosmos DBCommand cmd = new Cosmos DBCommand(select, conn);
Cosmos DBDataAdapter adapter = new Cosmos DBDataAdapter(cmd);
using (adapter) {
DataTable table = new DataTable();
adapter.Fill(table);
...
}
}
More Than Read-Only: Full Update/CRUD Support
Cosmos DB Data Provider goes beyond read-only functionality to deliver full
support for Create, Read, Update, and Delete operations (CRUD). Your end-users can interact
with the data presented by the Cosmos DB Data Provider as easily as interacting with
a database table.
using (Cosmos DBConnection connection = new Cosmos DBConnection(connectionString)) {
Cosmos DBDataAdapter dataAdapter = new Cosmos DBDataAdapter(
"SELECT Id, Where FROM DocumentDB", connection);
dataAdapter.UpdateCommand = new Cosmos DBCommand(
"UPDATE DocumentDB SET Where = @Where " +
"WHERE Id = @ID", connection);
dataAdapter.UpdateCommand.Parameters.AddWithValue("@Where", "Where");
dataAdapter.UpdateCommand.Parameters.AddWithValue("@Id", "80000173-1387137645");
DataTable DocumentDBTable = new DataTable();
dataAdapter.Fill(DocumentDBTable);
DataRow firstrow = DocumentDBTable.Rows[0];
firstrow["Where"] = "New Location";
dataAdapter.Update(DocumentDBTable);
}
ADO.NET Provider Performance
With traditional approaches to remote access, performance bottlenecks can spell disaster
for applications. Regardless if an application is created for internal use, a commercial project, web, or mobile
application, slow performance can rapidly lead to project failure. Accessing data from any remote source has the potential
to create these problems. Common issues include:
- Network Connections - Slow network connections and latency issues are common in mobile applications.
- Service Delays - Delays due to service interruptions, resulting in server hardware or software updates.
- Large Data - Intentional or unintentional requests for large amounts of data.
- Disconnects - Complete loss of network connectivity.
The CData ADO.NET Provider for Cosmos DB solves these issues by supporting powerful smart caching technology that can greatly
improve the performance and dramatically reduce application bottlenecks.
Smart Caching
Smart caching is a configurable option that works by storing queried data into a local database. Enabling smart
caching creates a persistent local cache database that contains a replica of data retrieved from the remote source.
The cache database is small, lightweight, blazing-fast, and it can be shared by multiple
connections as persistent storage.
Caching with our ADO.NET Providers is highly configurable, including options for:
-
Auto Cache - Maintain an automatic local cache of data on all requests. The provider will automatically
load data into the cache database each time you execute a SELECT query. Each row returned by the query will
be inserted or updated as necessary into the corresponding table in the cache database.
-
Explicit Cache - Cache only on demand. Developers decide exactly what data gets stored in the cache
and when it is updated. Explicit caching provides full control over the cache contents by using explicit
execution of CACHE statements.
- No Cache - All requests access only live data and no local cache file is created.
This powerful caching functionality increases application performance and allows applications to disconnect
and continue limited functioning without writing code for additional local storage and/or
data serialization/deserialization.
More information about ADO.NET Provider caching and best caching practices is available in the included
help files.
Visual Studio Integration & Server Explorer
Working with the new Cosmos DB ADO.NET Provider is easy. As a fully-managed .NET Data Provider, the Cosmos DB Data Provider
integrates seamlessly with the Visual Studio development environment as well as any .NET application.
As an ADO.NET Data Provider, Cosmos DB ADO.NET Provider can be used to access and explore
Azure Cosmos DB data directly from the Visual Studio Server Explorer.
It's easy. As a standard ADO.NET adapter, developers can connect the Server Explorer to Cosmos DB ADO.NET Provider
just like connecting to any standard database.
- Add a new Data Connection from the Server Explorer and select the Azure Cosmos DB Data Source
- Configure the basic connection properties to access your Azure Cosmos DB account data.
Explore all of the data available! Cosmos DB ADO.NET Provider makes it easy to access live Azure Cosmos DB data from Visual Studio.
- After configuring the connection, explore the feeds, views, and services provided by the Azure Cosmos DB Data Source.
- These constructs return live Azure Cosmos DB data that developers can work with directly from within Visual Studio!
Developer Integration: Databind to Cosmos DB
Connecting Web, Desktop, and Mobile .NET applications with Azure Cosmos DB is just like working with SQL Server. It is even
possible to integrate Cosmos DB ADO.NET Provider into applications without writing code.
Developers are free to access the Cosmos DB ADO.NET Provider in whatever way they like best. Either visually through
the Visual Studio Winforms or Webforms designers, or directly through code.
- Developers can connect the Azure Cosmos DB Data Source directly to form components by configuring the object's smart tags.
- Add a new Data Connection from the Server Explorer and select the Azure Cosmos DB Data Source. Then, select the
feed, view, or services you would like to connect the object to.
Done! It's just like connecting to SQL Server.
- Once the object is bound to the data source, applications can easily interact with Azure Cosmos DB data with full read/write (CRUD) support.