Thursday, April 9, 2009

Get Oracle Client Version

I've seen this all over the web using tnsping.exe or sqlplus..both of which are not guaranteed to be on the clients machine.. Some still would try calling a function of oci.dll that gives you the client version..but that function is not supported below i believe version 9 (dont quote me on that..i know its in 10, and i know its not in 8)

So this my contribution, and what i think to be the best way to get the oracle client version programaticalyaly..

Note: No error checking done here..

c#:

//Load oracle
lp_oci_dll = LoadLibraryExA("oci.dll", IntPtr.Zero, 8);

//Gets the path of oci.dll
System.Text.StringBuilder ls_buffer = new System.Text.StringBuilder(1024);
GetModuleFileNameA(lp_oci_dll, ls_buffer, 1024);

//Get oracle version
FileVersionInfo l_file_info = FileVersionInfo.GetVersionInfo(ls_buffer.ToString());
ls_ret = l_file_info.FileVersion;