C# to connect to a Progress Database

1

I'm trying to develop a program that will connect to a Progress Database (9.1E) using C# (Visual Studio 2010 Ultimate), but I first need to get a connection string to the Progress Database from the C# program.

I have tried the following, but I'm unsuccessful in establishing a connection to the Progress database. I'm not sure what the connection string should look like, but here's what I have before I start expanding everything. Also, I'm not sure what the DSN name should be.

private void downloadData_Click(object sender, RoutedEventArgs e)
{
    try
    {
        string connectString = "DSN = QADDB; Host = ipaddress; DB = dbname; UID = user; PWD = password;";
        IDbConnection dbConn = new OdbcConnection(connectString);
        dbConn.Open();
        IDbCommand dbCommand = dbConn.CreateCommand();
        string sqlstr = "SELECT pt_part FROM pt_mstr";
        dbCommand.CommandText = sqlstr;
        IDataReader reader = dbCommand.ExecuteReader();
        while (reader.Read())
        {
            string part = (string)reader["pt_part"];
            gridview.Items.Add(part);
        }
        reader.Close();
        reader = null;
        dbCommand.Dispose();
        dbCommand = null;
        dbConn.Close();
        dbConn = null;
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }
}

The error message says:

System.Data.Odbc.OdbcException (0X80131937): ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

c#
openedge
progress-db
asked on Stack Overflow Jun 16, 2015 by Jim S. • edited Oct 15, 2015 by Wai Ha Lee

2 Answers

2
string connectString = "DSN=QADDB;uid=username;pwd=password;host=hostname;port=port#;db=dbname;";
using (OdbcConnection dbConn = new OdbcConnection(connectString));
{
    try
    {
        dbConn.Open();
    } catch (Exception)
    {
        mRtnVar = "Couldn't Connect";
        return mRtnVar
    }   
    string sqlstr = string.Format(@"SELECT ""FieldName"" FROM PUB.DataBase WHERE ""FieldName"" = 'value'");
    using (OdbcCommand comm = new OdbcCommand(sqlstr, dbConn))
    {
        using (OdbcDataReader reader = dbConn.ExecuteReader())
        {
            if (reader.Read())
            {
                mRtnVar = reader["FieldName"].ToString();
            }
        }
    } 
    return mRtnVar
}      
answered on Stack Overflow Oct 15, 2015 by jon825 • edited Oct 15, 2015 by Ḟḹáḿíṅḡ Ⱬỏḿƀíé
1

In your connection string, set the port of your Progress database:

PORT=20931;

answered on Stack Overflow Jun 16, 2015 by Ricardo Pontual • edited Feb 27, 2017 by Ricardo Pontual

User contributions licensed under CC BY-SA 3.0