我从测试服务器连接到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。