Skip to content

Instantly share code, notes, and snippets.

@richardschoen
Created February 26, 2020 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richardschoen/3ac6a84151f2f9e5830716849f188b5d to your computer and use it in GitHub Desktop.
Save richardschoen/3ac6a84151f2f9e5830716849f188b5d to your computer and use it in GitHub Desktop.
Test IBMi Access ODBC Driver on Linux, Windows or IBM i
using System;
using System.Text;
using System.Data;
using System.Data.Odbc;
using System.Collections.Generic;
namespace OdbcCoreTest1
{
// https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_73/rzaik/connectkeywords.htm
// https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_71/rzaik/rzaikodbc64bitrestrictions.htm
// IBMi access drivers
class Program
{
static void Main(string[] args)
{
int exitcode = 0;
try
{
// Connection string passed in on command line. DSN=LOCAL;NAM=1; or whatever ODBC you want to test.
string connstring = "";
if (args.Length > 0)
{
connstring = args[0];
} else {
connstring = "DSN=*LOCAL;NAM=1";
}
// Log connection string
Console.WriteLine(connstring);
// Get connection
IDbConnection conn = new OdbcConnection(connstring);
// Open connection
Console.WriteLine("Before Open");
conn.Open();
Console.WriteLine("After Open");
// Get command and run query
Console.WriteLine("Before Query");
string sql = "select lstnam from qiws/qcustcdt ";
IDbCommand cmd = conn.CreateCommand();
cmd.CommandText = sql;
Console.WriteLine("Before Reader");
cmd.CommandType = System.Data.CommandType.Text;
// Execute reader to query. This blows on Linux, Works on IBMi and Windows
IDataReader rdr = cmd.ExecuteReader();
{
Console.WriteLine("Before Field Count");
Console.WriteLine("Fields:" + rdr.FieldCount);
rdr.Close();
}
Console.WriteLine("After Reader");
Console.WriteLine("After Query");
exitcode = 0;
} catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
exitcode = 99;
}
finally
{
Environment.Exit(exitcode);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment