Oracle没有使用.Net 4.0连接到远程服务器

时间:2014-04-07 10:01:34

标签: c# oracle

我从测试服务器连接到oracle数据库时遇到问题。贝娄是我的代码片段。

             using Oracle.DataAccess.Client;
             using Oracle.DataAccess.Types;
             private static string GetConnectionString()
     {
    String connString = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=IP_Address)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=Service_Name)));User Id=hook;Password=Password;";

    return connString;
}

    private string ConnectingToOracle()
     {  
    string connectionString = GetConnectionString();
    using (OracleConnection connection = new OracleConnection())

        try
        {
            connection.ConnectionString = connectionString;

            connection.Open();

            OracleCommand command = connection.CreateCommand();
            string sql = " select * from sgmp.web_portal1   where account_no= '" + customerIdField.Value.ToString().Trim() + "'";
            command.CommandText = sql;
            OracleDataReader reader = command.ExecuteReader();
            if (reader.HasRows)
            {
                while (reader.Read())

                {
                    Session["ClientName"] = (string)reader["Customer_Name"];
                    return (string)reader["Customer_Name"];

                }
            }
            else
            {
                resp.Text = "Client ID '" + customerIdField.Value.ToString().Trim() + "' does not exist in records";
                return "none";
            }


            return "none";
        }
        catch (OracleException ex)
        {
            resp.Text = ex.Message + " reasons ..";
            return "mmm";

        }
}

我没有任何异常,我无法连接。 问候。 我后来第一次使用Oracle。

1 个答案:

答案 0 :(得分:0)

我在这里找到了解决方案:http://support.microsoft.com/kb/255084我需要做的就是步骤1到5