My Code is below:
MySqlConnectionStringBuilder conn_string = new MySqlConnectionStringBuilder();
conn_string.Server = "mysql.***********.com";
conn_string.UserID = "********";
conn_string.Password = "********";
conn_string.Port = 3306;
conn_string.Database = "*********";
var connectionString = conn_string.ToString();
var connection = new MySqlConnection(connectionString);
connection.Open();
The error that I get is System.TimeoutException
Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
The code worked before when I was on a different network, but now that I have changed networks it no longer works and I get a timeout error on the connection.Open(); command.
Any ideas on what is wrong? I know that the database/server and even the computer I'm using has not changed but my network has.
Related
How can I get/inspect the certificate used on SQL Server to encrypt the connection?
I need to retrieve and inspect the certificate, and if possible do some custom validation
This code works for most things, except SQL Server it just times out
var sqlServer = "sqlserver-fqdn";
using (var client = new TcpClient())
{
client.SendTimeout = 10000;
client.ReceiveTimeout = 10000;
await client.ConnectAsync(sqlServer, 1433).ConfigureAwait(false);
using (var stream = client.GetStream())
using (var sslStream = new SslStream(stream, false,
(sender, certificate, chain, policyErrors) =>
{ /* do some validation */ }, null))
{
sslStream.AuthenticateAsClient(sqlServer);
}
}
Throws exception:
System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond..
---> System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Setting ServicePointManager.ServerCertificateValidationCallback += CertificateCallBack; has no effect, it's only used for http clients
I have setup the following connection factory
var factory = new ConnectionFactory() {
HostName = this.ApplicationConfigurationManager.QueueHostname,
UserName = ...,
Password = ...,
Ssl = new SslOption
{
Enabled = true,
ServerName = this.ApplicationConfigurationManager.QueueHostname,
AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateNameMismatch | SslPolicyErrors.RemoteCertificateChainErrors
}
};
The factory endpoint correctly shows as {amqp://localhost:5671}, as 5671 is for SSL, 5672 is for unsecured.
Note that locally I have not yet enabled SSL for RabbitMQ.
What I notice is that when I create a connection:
using (var connection = factory.CreateConnection())
and inspect the remote endpoint, it shows as {[::1]:5672}.
Why? I would expect it to try to connect to 5671 and fail (correctly, as I have not enabled it yet).
Does RabbitMQ ConnectionFactory fallback to 5672 (unsecure) if it finds out that SSL (5671) is not enabled?
I have the below code that connects to RabbitMQ on my local machine but when I change Host name from localhost to my servername it fails and returns the error
var factory = new ConnectionFactory();
factory.UserName = "myuser";
factory.Password = "mypassword";
factory.VirtualHost = "/";
factory.Port = AmqpTcpEndpoint.UseDefaultPort;
factory.HostName = "localhost";
As soon as I change HostName as below, it returns error
factory.HostName = "myserver";
Exception: None of the specified endpoints were reachable
The AMQP operation was interrupted: AMQP close-reason, initiated by
Library, code=0, text=\"End of stream\", classId=0, methodId=0,
cause=System.IO.EndOfStreamException: Peer missed 2 heartbeats with
heartbeat timeout set to 60 seconds
Instead of connecting this way, it's much easier to connect using a connection string like you would with sql.
Example C#:
var factory = new ConnectionFactory
{
Uri = ConfigurationManager.ConnectionStrings["RabbitMQ"].ConnectionString,
RequestedHeartbeat = 15,
//every N seconds the server will send a heartbeat. If the connection does not receive a heartbeat within
//N*2 then the connection is considered dead.
//suggested from http://public.hudl.com/bits/archives/2013/11/11/c-rabbitmq-happy-servers/
AutomaticRecoveryEnabled = true
};
return factory.CreateConnection();
web.config or app.config
<connectionStrings>
<add name="RabbitMQ" connectionString="amqp://{username}:{password}#{servername}/{vhost}" />
</connectionStrings>
On server, it looks like Host Name is configured different. My Admin looked at logs and looked at configuration and provided me with the Host Name on server.
var factory = new ConnectionFactory();
factory.UserName = "myuser";
factory.Password = "mypassword";
factory.VirtualHost = "/filestream";
factory.Port = AmqpTcpEndpoint.UseDefaultPort;
factory.HostName = "myserver";
So I'm trying to connect to an Oracle database using the Oracle.ManagedDataAccess-library, where I'm using the following datasource:
(DESCRIPTION =(SOURCE_ROUTE = YES)
(ADDRESS_LIST=
(ADDRESS = (PROTOCOL = TCP)(Host = PROXY-OracleConnectionManager)(Port = 1111))
(ADDRESS = (PROTOCOL = TCP) (Host = MAIN-DATABASE) (Port = 0000)))
(connect_data= (UR = A)(SERVICE_NAME = SERVICENAME)))
I'm also providing a user id and password.
We don't have any control over the database on our end, but as far as I know, they are using a connection manager as the first address, which should route us to the next address in the list if we are authenticated. This works when using this in Oracle SQL Developer but does not work programatically with Oracle.ManagedDataAccess.
This is how I build and use the connection string:
var connString = new OracleConnectionStringBuilder
{
{"User Id", settings.DbUserId},
{"Password", settings.DbUserPassword},
{"Data Source", settings.DbDataSource}
};
OracleConnection conn = new OracleConnection(connectionString.ToString())
conn.Open()
When I run this, I get the following error:
ORA-12537: Network Session: End of file
I suspect that the issue is the ADDRESS_LIST and that the routing doesn't work, but I can't say for sure. Anyone able to provide some insight?
I am trying to run ClientContext.ExecuteQuery() and I am getting the following error message:
"The underlying connection was closed: A connection that was expected to be kept alive was closed by the server." >> "Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."
My code is as follows:
ClientContext _clientcontext = new ClientContext("<URL of sharepoint site>");
NetworkCredential _cred = new NetworkCredential("userid", "password", "domain");
_clientcontext.Credentials = _cred;
Web _site = _clientcontext.Web;
CamlQuery _query = new CamlQuery();
try
{
_query.ViewXml = <View><Where><Eq><FieldRef Name=\"Created\"/><Value Type=\"DateTime\"><Today OffsetDays=\"-4\"/></Value></Eq></Where></View>";
List _splist = _site.Lists.GetById(new Guid("<GUID>"));
ListItemCollection _listitems = _splist.GetItems(_query);
_clientcontext.Load(_listitems);
_clientcontext.ExecuteQuery();