views:

179

answers:

3

Hi all,

I am making two build files using NAnt. The first aims to automatically compile Oracle 6i forms and reports and the second aims to compile Oracle 9i/10g forms and reports. Within the NAnt task is a C# script which prompts the developer for database credentials (username, password, database) in order to compile the forms and reports. I want to then run these credentials against the relevant database to ensure the credentials entered are correct and, if they are not, prompt the user to re-enter their credentials. My script currently looks as follows:

class GetInput
      {  
        public static void ScriptMain(Project project) 
        { 
          Console.Clear();
          Console.WriteLine("===================================================================");
          Console.WriteLine("Welcome to the Compile and Deploy Oracle Forms and Reports Facility");
          Console.WriteLine("===================================================================");
          Console.WriteLine();

          Console.WriteLine("Please enter the acronym of the project to work on from the following list:");
          Console.WriteLine();
          Console.WriteLine("--------");
          Console.WriteLine("- BCS");
          Console.WriteLine("- COPEN");
          Console.WriteLine("- FCDD");
          Console.WriteLine("--------");
          Console.WriteLine();
          Console.Write("Selection: ");
          project.Properties["project.type"] = Console.ReadLine();              
          Console.WriteLine();

          Console.Write("Please enter username: ");
          string username = Console.ReadLine();
          project.Properties["username"] = username;
          string password = ReturnPassword();
          project.Properties["password"] = password
          Console.WriteLine();
          Console.Write("Please enter database: ");
          string database = Console.ReadLine();
          project.Properties["database"] = database
          Console.WriteLine();

          //Call method to verify user credentials

          Console.WriteLine();
          Console.WriteLine("Compiling files...";
        }

        public static string ReturnPassword()
        {
            Console.Write("Please enter password: ");
            string password = "";
            ConsoleKeyInfo nextKey = Console.ReadKey(true);

            while (nextKey.Key != ConsoleKey.Enter)
            {
                if (nextKey.Key == ConsoleKey.Backspace)
                {
                    if (password.Length > 0) 
                    { 
                        password = password.Substring(0, password.Length - 1); 
                        Console.Write(nextKey.KeyChar); 
                        Console.Write(" "); 
                        Console.Write(nextKey.KeyChar); 
                    } 
                } 
                else 
                { 
                    password += nextKey.KeyChar; 
                    Console.Write("*"); 
                } 
                nextKey = Console.ReadKey(true); 
            }   
                return password;
          }
      }  

Having done a bit of research, I find that you can connect to Oracle databases using the System.Data.OracleClient namespace clicky. However, as mentioned in the link, Microsoft is discontinuing support for this so it is not a desireable solution. I have also fonud that Oracle provides its own classes for connecting to Oracle databases clicky. However, this only seems to support connecting to Oracle 9 or newer databases (clicky) so it is not feasible solution as I also need to connect to Oracle 6i databases.

I could achieve this by calling a bat script from within the C# script, but I would much prefer to have a single build file for simplicity. Ideally, I would like to run a series of commands such as is contained in the following .bat script:

rem -- Set Database SID --
set ORACLE_SID=%DBSID%

sqlplus -s %nameofuser%/%password%@%dbsid%
set cmdsep on
set cmdsep '"'; --"
set term on
set echo off
set heading off
select '========================================' || CHR(10) || 'Have checked and found both Password and ' || chr(10) || 'Database Identifier are valid, continuing ...' || CHR(10) || '========================================' from dual;

exit;

This requires me to set the environment variable of ORACLE_SID and then run sqlplus in silent mode (-s) followed by a series of sql set commands (set x), the actual select statement and an exit command. Can I achieve this within a c# script without calling a bat script, or am I forced to call a bat script? Thanks in advance!

+1  A: 

You may not have a problem.

You comment that "this only seems to support connecting to Oracle 9 or newer databases so it is not feasible solution as I also need to connect to Oracle 6i databases".

The "6i" designation refers to the forms and reports. Although there was a Oracle v6 database release, it was over 15 years ago and it is highly unlikely that you would be connecting to a database running that version of the RDBMS software.

dpbradley
A: 

It's a fact that Microsoft is discontinuing the System.Data.OracleClient, as it was buggy under some usage conditions and it has always been preferable to go with the Oracle .NET Data Provider, as it is the one that has worked, and still does, best against Oracle.

As an alternative for connecting to the 6i database, depending on whether it is doable in your particular situation, an ODBC DSN might be interesting, isn't it?

Otherwise, if the Microsoft Oracle Client Data Provider works good for your setup, just try to get a hand on the assembly itself and supply it with your application deployment. I guess this could be worthy.

Will Marcouiller
+2  A: 

Oracle forms 6i is not database. It's software for creating forms and reports and it can access different versions of Oracle RDBMS.
First version of Oracle forms 6i was released to work with Oracle 8 RDBMS, but it could work with newer versions. More details on this you can find on Wikipedia article on Oracle Forms.

You should find out what versions of database you have in production. Since you have SQL*plus and ORACLE_SID, just connect to all of your databases and first thing you'll see is server version.

You probably don't have RDBMS's older than 9i because Oracle stopped supporting v8 in 2006. Support for v9 will end in two months - on July 2010. Here you can find Oracle Lifetime Support Policy documents for all Oracle products. For RDBMS support policy read Lifetime Support Policy: Oracle Technology Products

zendar
Thanks for your response. I incorrectly assumed that the forms and reports version matched the RDBMS version. I have now found that the organisation I am doing this for is using Oracle 8i, 9i and 10g DBs. So, Oracle Data Provider for .NET is a feasible solution. I don't think it is worth downloading and using though since it will only be used to run this script. I really just want to be able to use C# to run system commands from the command prompt, much like a bat script does. Can anyone help me with this?
Mike M
Never mind, I have found the answer to my question now at http://stackoverflow.com/questions/1469764/c-run-command-prompt-commands Thanks for your help nonetheless!
Mike M