aca
aca
CC#
Created by aca on 11/9/2023 in #help
❔ ✅ Why am I getting error message CS0184?
No description
51 replies
CC#
Created by aca on 10/19/2023 in #help
❔ Connection Timeout argument passed doesn't work for a SqlConnection
I have the following connection string:
<add name="DatabaseServerInstance"
connectionString="Server=xx.xx.x.xx; Database=db; User Id=user; Password=pass; TrustServerCertificate=true; Connection Timeout=2;" />
<add name="DatabaseServerInstance"
connectionString="Server=xx.xx.x.xx; Database=db; User Id=user; Password=pass; TrustServerCertificate=true; Connection Timeout=2;" />
I have a WPF with a control calling a MessageBox to show whether the connection to the database is established or not and I want Connection.Open() to terminate early instead of the user having to wait 15 seconds for the failed connection message to be displayed, but Connection Timeout=2 seems to do nothing. An open connection gives an instantaneous response, while the failed connection despite the argument, loads with the average time no matter what the timeout is set to. This is the code for the sqlconnection call:
public class SqlPusher
{
private static SqlCommand command = new SqlCommand();
private static string connectionString = ConfigurationManager.ConnectionStrings["DatabaseServerInstance"].ConnectionString;

public Boolean TestConnection()
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
try
{
connection.Open();
return true;
}
catch (SqlException)
{
return false;
}
}
}

}
public class SqlPusher
{
private static SqlCommand command = new SqlCommand();
private static string connectionString = ConfigurationManager.ConnectionStrings["DatabaseServerInstance"].ConnectionString;

public Boolean TestConnection()
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
try
{
connection.Open();
return true;
}
catch (SqlException)
{
return false;
}
}
}

}
90 replies