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#:
  1. //Load oracle  
  2. lp_oci_dll = LoadLibraryExA("oci.dll", IntPtr.Zero, 8);  
  3.                   
  4. //Gets the path of oci.dll  
  5. System.Text.StringBuilder ls_buffer = new System.Text.StringBuilder(1024);  
  6. GetModuleFileNameA(lp_oci_dll, ls_buffer, 1024);  
  7.   
  8. //Get oracle version  
  9. FileVersionInfo l_file_info = FileVersionInfo.GetVersionInfo(ls_buffer.ToString());  
  10. ls_ret = l_file_info.FileVersion;