InterSystems.Data.IRISClient 2.6.0
IRISClient
IRISClient includes an ADO.NET driver that provides relational access to InterSystems IRIS. It also includes IRIS Native SDK that can be used to call ObjectScript classmethods and functions, manipulate ObjectScript class instances, and access globals.
Getting started
Install the package
Install the IRISClient library for .NET with NuGet
dotnet add package InterSystems.Data.IRISClient
The .nupkg file is distributed with IRIS under <IRIS install location>/dev/dotnet/bin/. Alternatively, the DLL files are also available under their corresponding versions and can be added as dependencies directly.
Prerequisites
You need an IRIS instance to interact with while using this package. The IRIS instance does not need to be on the same machine as the project using this package, but the project must be able to connect to the IRIS instance.
Examples
ADO.NET Driver
This is an example of code to connect to IRIS and execute SQL statements. Make sure to replace the connection information with values relevant to your system.
using InterSystems.Data.IRISClient;
string host = "localhost";
string port = "1972";
string username = "admin";
string password = "password";
string namespace = "USER";
string connectionString = $"Server = {host}; Port = {port}; Namespace = {nsp}; User ID = {username}; Password = {password}";
// Connect to IRIS
using IRISConnection connection = new IRISConnection(connectionString);
connection.Open();
string statement1 = "CREATE TABLE People(ID int, FirstName varchar(255), LastName varchar(255))";
string statement2 = "INSERT INTO People VALUES (1, 'John', 'Smith')";
string statement3 = "INSERT INTO People VALUES (2, 'Jane', 'Doe')";
string queryText = "SELECT * FROM People";
using IRISCommand cmd1 = new IRISCommand(statement1, connection);
using IRISCommand cmd2 = new IRISCommand(statement2, connection);
using IRISCommand cmd3 = new IRISCommand(statement3, connection);
using IRISCommand cmd4 = new IRISCommand(queryText, connection);
// ExecuteNonQuery() is used for CREATE, INSERT, UPDATE, and DELETE
cmd1.ExecuteNonQuery();
cmd2.ExecuteNonQuery();
cmd3.ExecuteNonQuery();
// ExecuteReader() is used for SELECT
using IRISDataReader reader = cmd4.ExecuteReader();
Console.WriteLine("SELECT query results: ");
while (reader.Read())
{
Console.WriteLine($"{reader.GetValue(0)}: {reader.GetValue(1)}, {reader.GetValue(2)}");
}
reader.Close();
Use Native SDK with ObjectScript Classes
This is an example of code to connect to IRIS and call ObjectScript class methods. This assumes the IRIS instance has a class, User.NativeTest, with a class method AreEqual and an instance method HaveBirthday.
string host = "localhost";
string port = "1972";
string username = "_SYSTEM";
string password = "SYS";
string nsp = "USER";
string connectionString = $"Server = {host}; Port = {port}; Namespace = {nsp}; User ID = {username}; Password = {password}";
// Establish a connection to IRIS
using IRISConnection connection = new IRISConnection(connectionString);
connection.Open();
// Use the connection to create an instance of the Native SDK
using IRIS iris = IRIS.CreateIRIS(connection);
// call a class method that tests if two values are equal
bool? areEqual = iris.ClassMethodBool("User.NativeTest", "AreEqual", 5, 7);
Console.WriteLine(areEqual);
// create a proxy object
using IRISObject obj = (IRISObject)iris.ClassMethodObject("User.NativeTest", "%New");
// set and get property values
obj.Set("name", "John Smith");
obj.Set("age", 30);
string name = obj.GetString("name");
// call instance method
obj.InvokeVoid("HaveBirthday");
long? age = obj.GetLong("age");
Console.WriteLine($"{name} is now {age} years old");
Use Native SDK with Globals
This is an example of interacting with globals in IRIS.
string host = "localhost";
string port = "1972";
string username = "_SYSTEM";
string password = "SYS";
string nsp = "USER";
string connectionString = $"Server = {host}; Port = {port}; Namespace = {nsp}; User ID = {username}; Password = {password}";
// Establish a connection to IRIS
using IRISConnection connection = new IRISConnection(connectionString);
connection.Open();
// Use the connection to create an instance of the Native SDK
using IRIS iris = IRIS.CreateIRIS(connection);
// set value of myGlobal to be myValue
iris.Set("myValue", "myGlobal");
// sets value of myGlobal at subscript to be 10
iris.Set(10, "myGlobal", "subscript");
// you can use an arbitrary number of subscripts, and they can be a string or number
iris.Set("abc", "myGlobal", 1, 2, 3);
iris.Set("xyz", "myGlobal", 1, 2, 3.5);
// modify a global value
iris.Set(15, "myGlobal", "subscript");
// get global values
string val1 = iris.GetString("myGlobal");
int? val2 = iris.GetInt32("myGlobal", "subscript");
string val3 = iris.GetString("myGlobal", 1, 2, 3);
string val4 = iris.GetString("myGlobal", 1, 2, 3.5);
Console.WriteLine($"^myGlobal = {val1}");
Console.WriteLine($"^myGlobal(\"subscript\") = {val2}");
Console.WriteLine($"^myGlobal(1, 2, 3) = {val3}");
Console.WriteLine($"^myGlobal(1, 2, 3.5) = {val4}");
// delete the global
iris.Kill("myGlobal");
Additional documentation
More information can be found in InterSystems ADO.NET Documentation and InterSystems Native SDK Documentation
No packages depend on InterSystems.Data.IRISClient.
.NET Framework 3.5
- No dependencies.
.NET Framework 4.0.3
- No dependencies.
.NET Framework 4.6.2
- No dependencies.
.NET 6.0
- No dependencies.
.NET 8.0
- No dependencies.
.NET 9.0
- No dependencies.