Entwickler-Ecke

Datenbanken (inkl. ADO.NET) - Host-Time von der DB (RDB)


soulgrinder - Do 25.10.07 14:03
Titel: Host-Time von der DB (RDB)
Hallo,

ich muss die DB-Host-Time auslesen in C#. Bis anhin habe ich das mit PowerBuilder mit Storade Procedure gemacht:

DECLARE get_host_date PROCEDURE FOR GET_HOST_DATE OUTPUT USING this;
EXECUTE get_host_date;
FETCH get_host_date INTO :ldt_timestamp;

Wie mache ich das in C#?
Danke


UGrohne - Fr 26.10.07 16:50

Ähm? Du hast doch eine Stored Procedure? Wieso holst Du Dir dann nicht den Rückgabewert derselben einfach?

Oder willst Du das aktuelle Datum und Zeit in Deiner Applikation haben? Dann hilft Dir

C#-Quelltext
1:
DateTime.Now                    


soulgrinder - Mi 31.10.07 09:44

Habe es herausgefunden:


C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
//DSN-Name, User-ID and password for the connection
            string source = "DSN=test-gamma1-archiv-r;Uid=...;Pwd=...";
        
            OdbcConnection connection = new OdbcConnection(source);
            try
            {
                OdbcCommand command = new OdbcCommand("{ ? = CALL GET_HOST_DATE(?) }", connection);
                command.CommandType = CommandType.StoredProcedure;

                OdbcParameter parameter = command.Parameters.Add("RETURN_VALUE", OdbcType.DateTime);
               
                parameter.Direction = ParameterDirection.ReturnValue;
                
                connection.Open();
                // datetime-output at the console
                Console.WriteLine(command.ExecuteScalar());
            
                command.Dispose();

                Console.ReadLine();
            }
            catch (Exception OdbcException)
            {
                System.Console.WriteLine(OdbcException.Message);
                Console.ReadLine();
            }
            finally
            {
                connection.Dispose();
                connection.Close();
            }


Die Problematik war, dass der neue Oracle-RDB-Treiber ab Version 3.0 keinen Returnwert mehr liefert. Die früheren Versionen schon.
Call wurde bei Oracle eröffnet.

Moderiert von user profile iconjasocul: C#-Tags hinzugefügt


Kha - Mi 31.10.07 12:16

Kleiner Tipp am Rande: Benutze statt try-finally besser

C#-Quelltext
1:
2:
3:
4:
using (DbConnection connection = ...) // ruft am Ende Dispose uns damit Close auf
  using (DbCommand ...) {
    ...
  }