Skip to main content

Motivation:

This is a short example to demonstrate how to access Data Virtuality via an ODBC connection in F#. Please keep in mind that this is not an F#/.NET code and the sample just shows a basic approach for the ODBC connection.

Requirements:

The system which shall access Data Virtuality Server needs to have at least the ODBC drivers installed. A DSN connection is also possible but requires the ODBC drivers as well. They can be obtained from the web server which is implemented in Data Virtuality (see https://datavirtuality.zendesk.com/hc/en-us/articles/115002027906-Components-downloadable-from-DV-site)

 

Simple code sample:

The following sample creates a connection string based on a DSN. It is then used for a new ODBC connection and the program executes the query "SELECT * FROM dwh.foo" on this connection.

Afterwards, the name of the first column of the result set is retrieved and all values for this column are printed.

 

open System

open System.Data.Odbc

 

><EntryPoint>]

let main argv =

    let connectionString = "DSN=DataVirtuality_32_A;username=admin;pw=admin;"

    let dvConn = new OdbcConnection(connectionString)

 

    let qComm = new OdbcCommand("SELECT * FROM dwh.foo",dvConn)

    qComm.Connection.Open()

    let result = qComm.ExecuteReader()

 

    let firstColumn = result.GetName(0)

    printfn "%A" firstColumn

    while result.Read() do printfn "%A" (result.GetValue(0))   

     

    result.Close()

    dvConn.Close()

 

    System.Console.ReadKey()

 

    0 // return an integer exit code

 

 

The point thing is the connection string which can be build based on a DSN or an ODBC driver

Connect via DSN

let connectionString = "DSN=DataVirtuality_32_A;username=admin;pw=admin;"

 

Connect via Driver and other information

let connectionString = "driver={DataVirtuality ANSI}; server=dv; port=35432; database=datavirtuality; uid=admin;pwd=admin";

Be the first to reply!

Reply