检查从C#应用程序到Oracle 10g数据库的连接 [英] check connection from C# app to oracle 10g database

查看:157
本文介绍了检查从C#应用程序到Oracle 10g数据库的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查从C#应用程序到Oracle 10g数据库的连接?

How can I check connection from C# app to oracle 10g database?

例如,我在机器上安装了Oracle服务器,IP为10.50.65.2。我在app.config中维护IP,端口。

For example I have Oracle server on machine with IP 10.50.65.2. I maintain IP, Port in app.config.

我将应用程序移动到另一个连接到另一个网络的PC上。我需要检查是否可能创建与数据库服务器正确的连接。

I move app to another pc connected to another network. I need check if it is possible create correct connection with database server.

如果不可能创建db连接我需要
只显示简单消息请修改db

If it is not possible create db connection I need show only simple message please modify db connection data in app.config.

推荐答案

为什么不尝试创建连接并捕获异常?

Why don't you just try to create the connection and catch the exception if it fails?

可能是这样的:

public bool CheckConnection()
{
    string connectionString = ""; //Get from configuraiton.
    using(var conn = new OracleConnection(connectionString))
    {
        try
        {
            conn.Open();
            return true;
        }
        catch
        {
            return false;
        }
    }
}

这篇关于检查从C#应用程序到Oracle 10g数据库的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆