Groups | Blog | Home
all groups > dotnet ado.net > may 2007 >

dotnet ado.net : How do I tell if the Oracle client is installed


David Thielen
5/19/2007 4:36:00 PM
Hi;

The class OracleConnection is part of .NET and so is always available.
However, it does not work if the Oracle client software is not installed on a
user's system. How can I test for that being installed so I don't offer
Oracle as a choice if it can't be used?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm

Manish Bafna
5/19/2007 11:17:00 PM
Hi,
Try this code:
Microsoft.Win32.RegistryKey key =
Microsoft.Win32.Registry.LocalMachine.OpenSubKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\ORACLE");

if(key == null)
MessageBox.Show("Oracle not installed on client machine");
Hope this helps.
--
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



[quoted text, click to view]
Manish Bafna
5/20/2007 3:19:13 AM
Hi,
A little correction in my code in previous post.It should be like this:
Microsoft.Win32.RegistryKey key =
Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Oracle");
if(key == null)
MessageBox.Show("Oracle not installed on client machine");
Hope this helps.
--
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



[quoted text, click to view]
David Thielen
5/20/2007 7:17:00 AM
That helps - it will tell me if Oracle has never been installed on a
computer. Unfortunately it does not work if Oracle was uninstalled.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm




[quoted text, click to view]
Manish Bafna
5/20/2007 9:56:01 PM
Hi,
Below method is not elegant one but simple and reliable.You can do something
like this:
using System;
using System.Data;
using System.Data.OracleClient;

public bool IsOracleInstaled()
{
string connectionString = GetConnectionString();

using (OracleConnection connection = new OracleConnection(connectionString))
{
try
{
connection.Open();
return true;

}
catch (Exception ex)
{
return false;
}
}
}

--
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



[quoted text, click to view]
v-wywang NO[at]SPAM online.microsoft.com
5/22/2007 12:00:00 AM

I agree with Manish.
In my opnion, trying to connect Oracle server in coding is the simplest
(safest) way to check whether Oracle client software has been installed on
machine.

Have a great day,
Sincerely,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
David Thielen
5/22/2007 6:13:03 AM
I don't think that will work as it will fail if the connection string is bad
too and I have no way of knowing what a good connection string is.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm




[quoted text, click to view]
David Thielen
5/22/2007 10:04:00 PM
Hi;

The problem is I never want to give the user our Oracle connection dialog if
the Oracle client is not installed on their computer. So I need to know if
Oracle is installed before I get a connection string from them.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm




[quoted text, click to view]
v-wywang NO[at]SPAM online.microsoft.com
5/23/2007 12:00:00 AM
Hi Dave
Thanks for your reply.

Have you tried "OracleConnectionStringBuilder"? This is a new class
introduced in .net framework 2.0. Pass ServerName, PassWord and UserName to
this builder. It will build a correct connection for you. Hope this helps.

http://msdn2.microsoft.com/en-us/library/system.data.oracleclient.oracleconn
ectionstringbuilder.aspx
[OracleConnectionStringBuilder Class]

Please let me know if you still have any concern on this. I'm glad to work
with you.
Sincerely,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
v-wywang NO[at]SPAM online.microsoft.com
5/23/2007 12:28:11 PM
Hi Dave,
Thanks for your reply.

As far as I know, we can detect whether the Oracle Client has been
installed by Register key or connection.

If you truly do not want to get a connection string from user, I'm afraid
the only way is checking RegistryKey.

Another choice, you may use both. You may check the registry key and then
try to connect Oracle Database....

I also appreciate for any other better solution.
Sincerely,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Manish Bafna
7/30/2007 4:52:03 AM
Hi,
I know it is now too late but i have found solution for what you were
looking.Try this code:
If( Environment.ExpandEnvironmentVariables("%ORACLE%").ToString().ToUpper()
<> "%ORACLE%")
MessageBox.Show("Oracle is installed")

I have found that if oracle is installed then
Environment.ExpandEnvironmentVariables("%ORACLE%").ToString() gives path to
installation folder.
--
Hope this answers your question although late.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



[quoted text, click to view]
AddThis Social Bookmark Button