On my application I need to connect at client database(SqlServer) only to see if we can connect. These are my connection strings from web.config(the values are not that way, I´ve changed the ip, user and pwd)
<add name="ConnectionStringLibracom" connectionString="Data Source=192.168.1.45\SqlServer2008;Initial Catalog=xxx;user=xxx;pwd=xxx;Application Name=MES"
providerName="System.Data.SqlClient" /> (MINE)
<add name="ConnectionStringMigplus" connectionString="Data Source=999.99.999.99;Initial Catalog=xxx;user=xxx;pwd=xxx"
providerName="System.Data.SqlClient" /> (CLIENT)
but this piece of code hangs my entire application(when I say that it hangs, I mean that it dont let my application to connect to our DB). I´m executing it at Default.aspx on Load event:
protected void Page_Load(object sender, EventArgs e)
{
if (!TestaIntegracaoErpMigplus())
{
lblMensagemIntegracao.Visible = true;
Session["Integracao"] = false;
}
else
Session["Integracao"] = true;
}
protected static bool TestaIntegracaoErpMigplus()
{
string connectionStringMigplus = WebConfigurationManager.ConnectionStrings["ConnectionStringMigplus"].ConnectionString;
bool ret = false;
using (SqlConnection Conn = new SqlConnection(connectionStringMigplus))
{
try
{
Conn.Open();
if (Conn.State == ConnectionState.Open)
{
ret = true;
}
}
catch (SqlException)
{
ret = false;
}
}
return ret;
}
@EDIT: The problem is not if I can connect to the server or not, the problem is: when I´m trying to connect to that db my asp.net website frozen to new requests at others page
Task
and useWait
function with timeout – TunefulMARS
may help youMultipleActiveResultSets=true;
. – Monroy