13.07.2015 Views

Using the Caché Managed Provider for .NET - InterSystems ...

Using the Caché Managed Provider for .NET - InterSystems ...

Using the Caché Managed Provider for .NET - InterSystems ...

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Using</strong> <strong>Caché</strong> ADO <strong>Provider</strong> Classes4.1 Introduction to ADO <strong>Provider</strong> ClassesA project using <strong>the</strong> <strong>Caché</strong> ADO <strong>Provider</strong> classes can be quite simple. Here is a complete, workingconsole program that opens and reads an item from <strong>the</strong> Sample.Person database:using System;using <strong>InterSystems</strong>.Data.CacheClient;using <strong>InterSystems</strong>.Data.CacheTypes;namespace TinySpace {class Tiny<strong>Provider</strong> {[STAThread]static void Main(string[] args) {}CacheConnection CacheConnect = new CacheConnection();CacheConnect.ConnectionString = "Server = localhost; "+ "Port = 1972; " + "Namespace = SAMPLES; "+ "Password = SYS; " + "User ID = _SYSTEM;";CacheConnect.Open();string SQLtext = "SELECT * FROM Sample.Person WHERE ID = 1";CacheCommand Command = new CacheCommand(SQLtext, CacheConnect);CacheDataReader Reader = Command.ExecuteReader();while (Reader.Read()) {Console.WriteLine("Tiny<strong>Provider</strong> output: \r\n "+ Reader[Reader.GetOrdinal("ID")] + ": "+ Reader[Reader.GetOrdinal("Name")]);};Reader.Close();Command.Dispose();CacheConnect.Close();} // end Main()} // end class Tiny<strong>Provider</strong>This project contains <strong>the</strong> following important features:• The <strong>Using</strong> statements provide access to <strong>the</strong> CacheClient assembly:using <strong>InterSystems</strong>.Data.CacheClient;using <strong>InterSystems</strong>.Data.CacheTypes;• The CacheConnection object is used to create and open a connection to <strong>the</strong> <strong>Caché</strong> SAMPLESnamespace:CacheConnection CacheConnect = new CacheConnection();CacheConnect.ConnectionString = "Server = localhost; "+ "Port = 1972; " + "Namespace = SAMPLES; "+ "Password = SYS; " + "User ID = _SYSTEM;";CacheConnect.Open();• The CacheCommand object uses <strong>the</strong> CacheConnection object and an SQL statement to open <strong>the</strong>instance of Sample.Person that has an ID equal to 1.string SQLtext = "SELECT * FROM Sample.Person WHERE ID = 1";CacheCommand Command = new CacheCommand(SQLtext, CacheConnect);20 <strong>Using</strong> <strong>the</strong> <strong>Caché</strong> <strong>Managed</strong> <strong>Provider</strong> <strong>for</strong> .<strong>NET</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!