I'm having difficulties manually debugging an .NET application where the Guid values differ from .NET to Oracle.
- Where C# reads:
17D89D326C2142D69B989F5201288DBF
- Oracle reads:
329DD817216CD6429B989F5201288DBF
How would I be able to manually debug, i.e., from C#'s GUID be able to paste that value in an oracle query and get the correct results (and viceversa)?
Just use always your standard
GUID
in .NET...When you want to insert some
GUID
into Oracle you just callGuid.ToString ( "N")
and feed that string to Oracle (in this example the param name isMyNETVAL
):When you read a
RAW
from Oracle you use:Then you can feed the returned
MyNETVal
intonew Guid (MyNETVal)
.This way your code always deals with the .NET format and the byte switching occurs in the Oracle-DB... you don't polute your code with conversion code and can keep the code code the same when switchig to other DBs - just change the SQL and you are up and running... the SQL could get simpler with other DBs because some of them follow the GUID format of Windows...
If you need to convert a GUID to RAW from PL/SQL can use this function:
I just had this same issue when storing and reading Guids from Oracle.
Jon's answer is correct for querying but if your app needs to store and read Guids from Oracle, use the FlipEndian function from this thread:
.NET Native GUID conversion
The flip is only required when reading back from Oracle.
When writing to Oracle use Guid.ToByteArray() as normal.
I spent TOO much time trying to get this simple task accomplished.
Steve
If you look at the values involved (in pairs) of hex digits you can see that the last 7 bytes are the same in both cases, but the first 9 are switched around a bit.
Going from your example, but rewriting each pair in the .NET as 00, 11, 22 etc and switching the relevant byte of Oracle as well we get:
.NET:
Oracle:
So it should be fairly easy to write code to switch round the relevant bytes. (I'm pretty sure I wrote some code to do this in a previous job, in fact.)
To switch round the bytes, you'll just want to call
Guid.ToByteArray()
andnew Guid(byte[])
to get back to aGuid
.EDIT: As it happens, the switch-round above is exactly what the
Guid
constructor does when you pass it a byte array:Prints:
That may well make it considerably simpler to perform the switching... how were you getting hold of the values to start with? Is it just "how they're displayed in Oracle"?
EDIT: Okay, here are a couple of conversion functions - if you've got the data as text, they'll convert each way...