我有一个webapp,VS2013,C#和ASP.NET,我使用Oracle 12c作为DB,所以当我尝试从我的webapp连接到DB时,我收到了这个错误:ORA-12541:TNS:没有监听器,这个是我的代码:
public bool OpenConnection(Label lbl)
{
try
{
using (cn = new OracleConnection(WebConfigurationManager.ConnectionStrings["RegistroConnection"].ToString()))
{
if (cn.State == ConnectionState.Closed)
{
cn.Open();
}
}
return true;
}
catch (NullReferenceException nullExcept)
{
lbl.Text = "Caught error: ." + nullExcept.ToString();
return false;
}
catch (OracleException dbEx)
{
lbl.Text = "OraException - " + dbEx.Message;
return false;
}
catch (Exception ex)
{
Exception current;
current = ex;
while (current != null)
{
current = current.InnerException;
}
lbl.Text = "Db base exception - " + ex.GetBaseException().ToString();
return false;
}
}
我的webconfig上有连接字符串:
<connectionStrings>
<add name="RegistroConnection"
connectionString="Data Source=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST =myServer)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SID = sidname)));User Id=user;Password=password;"
providerName="Oracle.DataAccess.Client"/>
</connectionStrings>
已添加的dll是: - Oracle.DataAccess.Client
如果我尝试通过Sql Developer连接,我有一个成功的连接,但在我的webapp上我有这个错误:ORA-12541:TNS:没有监听器