C#连接到进度数据库

时间:2015-06-16 14:41:12

标签: c# openedge progress-db

我正在尝试开发一个使用C#(Visual Studio 2010 Ultimate)连接到Progress Database(9.1E)的程序,但我首先需要从C#程序获取Progress数据库的连接字符串

我尝试过以下操作,但是我没有成功建立与Progress数据库的连接。我不确定连接字符串应该是什么样子,但是在我开始扩展所有内容之前,这就是我所拥有的。另外,我不确定DSN名称应该是什么。

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());
    }
}

错误消息显示:

  

System.Data.Odbc.OdbcException(0X80131937):ERROR [IM002]   [Microsoft] [ODBC驱动程序管理器]未找到数据源名称,没有   指定默认驱动程序

2 个答案:

答案 0 :(得分: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
}      

答案 1 :(得分:1)

在您的连接字符串中,设置Progress数据库的端口:

PORT = 20931;