Connecting to progress OpenEdge Db from .net using ODBC

  • Thread starter progresscommunities@progr
  • Start date
Status
Not open for further replies.
P

progresscommunities@progr

Guest
Hi i installed the trial version in my pc and just wanted to have a quick app that was able to read from the database. but still i get errors connecting and i am unable to query the databse. could someone please hlpe me out? i dont know if the trial version will give you issues when connecting using ODBC, or if i am using wrong paramenters when buidling the connection string. Where do i find the port DSN... and the rest of the info to create connection string?



thanks



Brian





c# code



public static string GetODBCDriverName(string Database, string Version)

{

string ODBCDriverName = "";

RegistryKey registryKey = Registry.LocalMachine;

RegistryKey registrySubKey = registryKey.OpenSubKey(@"SOFTWARE\ODBC\ODBCINST.INI\");

String[] SubKeyNames = registrySubKey.GetSubKeyNames();

foreach (String KeyName in SubKeyNames){

if (KeyName.Contains(Database) && KeyName.Contains(Version)){

ODBCDriverName = KeyName;

break;

}}

registrySubKey.Close();

registryKey.Close();

return ODBCDriverName;

}



then

using the following code to connect to the database




OdbcConnectionStringBuilder odbcConnectionStringBuilder = new OdbcConnectionStringBuilder();

OdbcCommand odbcCommand;



int RecordFound = 0;



odbcConnectionStringBuilder.Driver = GetODBCDriverName("Progress", "11.2");

if (odbcConnectionStringBuilder.Driver == "")

{

Console.WriteLine(" ODBC Driver is not installed");

return -1;

}



odbcConnectionStringBuilder.Add("DSN", "SPORTS");

//odbcConnectionStringBuilder.Add("UID", "no-user");

//odbcConnectionStringBuilder.Add("PWD", "no-pass");

odbcConnectionStringBuilder.Add("DB", @"C:\OpenEdge\WRK\Db2.db"); // copy of database SPORTS

odbcConnectionStringBuilder.Add("HOST", "mypcname");

odbcConnectionStringBuilder.Add("PORT", "5162"); // i found this port inn the log file

using (OdbcConnection connection = new OdbcConnection(odbcConnectionStringBuilder.ConnectionString))

{

connection.Open();



try

{

odbcCommand = new OdbcCommand("SELECT COUNT(*) FROM pub.Invoice WHERE Invoicenum > 0", connection);

odbcCommand.CommandTimeout = 1;

object executeScalarResult = odbcCommand.ExecuteScalar();

RecordFound = Convert.ToInt32(executeScalarResult);

}

catch (Exception e)

{

Console.WriteLine(e.Message);

}

}

Continue reading...
 
Status
Not open for further replies.
Top