LoginSignup
1
1

More than 5 years have passed since last update.

VB.NETでInterSystems IRIS Platformのデータベースにアクセスする方法

Last updated at Posted at 2018-10-16

10月3日に発表されたInterSystems IRIS for Healthについて、VB.NETでの接続法を調べました。
(結論から言いますと、以前この項で紹介したVB.NETによるCache'の接続と殆ど同じです。)

1.InterSystems IRIS Platformのインストール(ディスクを使用)

2.右下のアイコン[IR]から、Studioを起動
image.png

3.テーブルとなるクラスを作成する(新規→クラスの作成から。ここではネームスペース"USER"の中に、MercForNLPというクラスを作成している。)
image.png

ソースコードは次の通り。contentFullの後ろについているMAXLANがないと、デフォルトの文字列は50文字ぐらいになる。

MercForNLP
Class User.MercForNLP Extends (%Persistent, %Library.Populate)
{

Property diseaseName As %String;

Property medicalDivision As %String;

Property dataType As %String;

Property contentFull As %String(MAXLEN = 100000);

4.VB.NETの準備
プロジェクトを新規作成し(ここではフォームアプリケーションを作成)、プロジェクト→参照の追加で
C:\InterSystems\IRIS\dev\dotnet\bin\4.5\InterSystems.Data.IRISClient.dll
C:\InterSystems\IRIS\dev\dotnet\bin\4.5\InterSystems.Data.GateWay64.dll
を追加する
image.png

Buttonを1つ作成し、IRISへの接続コードを記述する。VB.NET内コードの記述は次の通り。port=51773であることに注意する。ここではSQL文を使って、ID=1のデータをReader.Read()で読み出しています。また、これがクラウドにある場合(IRIS Platformではユーザー登録でクラウド上のIRISを利用できるようになります)でも、アドレス指定を変えるだけですので、操作法は共通です。

IrisConnectionTest.vb

Imports InterSystems.Data.IRISClient
Imports InterSystems.Data.IrisTypes

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim IrisConnect As IRISConnection = New IRISConnection()

        IrisConnect.ConnectionString = "Server = localhost; " + "Port = 51773; " + "Namespace = TESTSAMPLES; " + "Password = yourpass; " + "User ID = yourname;"
        IrisConnect.Open()

        Dim SQLtext As String = "SELECT * FROM SQLUser.MercForNLP WHERE ID = 1"
        Dim Command As New IRISCommand(SQLtext, IrisConnect)
        Dim Reader As IRISDataReader = Command.ExecuteReader()
        Dim smsg As String

        'While (Reader.Read())
        Reader.Read()
        smsg = "TinyProvider output: \r\n   " _
          + CStr(Reader(Reader.GetOrdinal("ID"))) + ": " _
          + Reader(Reader.GetOrdinal("contentFull"))
        Console.WriteLine(smsg)
            MsgBox(smsg)
        'End While

        Reader.Close()
        Command.Dispose()
        IrisConnect.Close()

    End Sub

End Class

実行結果は次の通りです。
image.png
image.png

IRISにはObjectBindingはまだありませんが、「つながる」仕組みを作るために今後実装が計画されているとの談話でした。CacheCommandを使って記述する方法で、接続性は担保できると考えています。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1