# Connecting F# via ODBC

**URL:** <https://community.cdata.com/t/connecting-f-via-odbc/831>\
**Category:** CData Virtuality \[Archived\]\
**Tags:** article, cdata-virtuality\
**Created:** [July 12, 2024, 4:26pm UTC](https://community.cdata.com/t/connecting-f-via-odbc/831 "2024-07-12T16:26:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous](https://avatars.discourse-cdn.com/v4/letter/a/8491ac/32.png) [@anonymous](https://community.cdata.com/u/anonymous)\
**Post date:** [July 12, 2024, 4:26pm UTC](https://community.cdata.com/t/connecting-f-via-odbc/831/1 "2024-07-12T16:26:02Z")

</div>

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&nbsp;[https://datavirtuality.zendesk.com/hc/en-us/articles/115002027906-Components-downloadable-from-DV-site](https://support.datavirtuality.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&nbsp;“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)_

_&nbsp;&nbsp;&nbsp; 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";`
