Question & Answer
Question
How do I create an OLEDB connection to PureData System for Analytics using C#?
Answer
The following is C# sample code and a sample data source string for making an OLEDB connection to PureData System for Analytics. It shows how to access a table called table in a database called DatabaseName on the host called hostname.
Provider=NZOLEDB;
Password=password;
password for the database
User ID=admin;
username for the user specified below to access the database
Data Source=hostname;
hostname of the NPS system
Initial Catalog=DatabaseName;
database name to which we are connecting.
Persist Security Info=True";
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
namespace MyProject {
class Program {
static void Main(string[] args)
{
Program obj = new Program();
obj.exeReader();
Console.WriteLine("END");
}
private string connString = "Provider=NZOLEDB;Password=password; User ID=admin; Data Source=hostname; Initial Catalog=DatabaseName; Persist Security Info=True";
public void exeReader()
{
System.Data.OleDb.OleDbConnection oConn = new System.Data.OleDb.OleDbConnection(connString);
System.Data.OleDb.OleDbCommand oCmd;
System.Data.OleDb.OleDbDataReader oReader;
oConn.Open();
oCmd = oConn.CreateCommand();
oCmd.CommandText = "SELECT COUNT(*) FROM table";
try {
oReader = oCmd.ExecuteReader();
while (oReader.Read()) {
Console.WriteLine(oReader["COUNT"].ToString());
}
oReader.Close();
}
catch (Exception e)
{
Console.WriteLine("Exception occured!");
}
oConn.Close();
}
}
}
Historical Number
NZ330267
Was this topic helpful?
Document Information
More support for:
IBM PureData System
Software version:
1.0.0
Document number:
461913
Modified date:
17 October 2019
UID
swg21569593