Autor Beitrag
soulgrinder
Hält's aus hier
Beiträge: 2



BeitragVerfasst: Do 25.10.07 14:03 
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
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: 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
ausblenden C#-Quelltext
1:
DateTime.Now					
soulgrinder Threadstarter
Hält's aus hier
Beiträge: 2



BeitragVerfasst: Mi 31.10.07 09:44 
Habe es herausgefunden:

ausblenden volle Höhe 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
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Mi 31.10.07 12:16 
Kleiner Tipp am Rande: Benutze statt try-finally besser
ausblenden C#-Quelltext
1:
2:
3:
4:
using (DbConnection connection = ...) // ruft am Ende Dispose uns damit Close auf
  using (DbCommand ...) {
    ...
  }