A timeout occured after 30000ms selecting a server using CompositeServerSelector - c#

I try to deploy my Mongo database in Mongolabs, everything works fine, and I create a new database. Please see my connectionstring.
public DbHelper()
{
MongoClientSettings settings = new MongoClientSettings()
{
Credentials = new MongoCredential[] { MongoCredential.CreateCredential("dbname", "username", "password") },
Server = new MongoServerAddress("ds011111.mongolab.com", 11111),
//ConnectTimeout = new TimeSpan(30000)
};
Server = new MongoClient(settings).GetServer();
DataBase = Server.GetDatabase(DatabaseName);
}
but when I try to connect the database it's shows error like:

Add "?connect=replicaSet" to the end of your connection string if connecting to MongoLab.
new MongoClient("mongodb://username:password#ds011111.mongolab.com:11111/db-name?connect=replicaSet")
This JIRA ticket has some details: https://jira.mongodb.org/browse/CSHARP-1160
Basically the default is to connect to a replica set member. But MongoLab's Single-Node settings are actually a single node replica set and this causes us to not trust it. Appending ?connect=replicaSet to your connection string will force the driver to move into replica set mode and all will work.
Found that info here.

I am replacing the connection string method in like below.
new MongoClient("mongodb://username:password#ds011111.mongolab.com:11111/db-name")
Now it's solved.
Please see the answer from Paul Lemke.

Make sure your current ip address is white-listed in mongo db server.
If you change your internet provider new IP needs to be white-listed.

Make Sure your auth db is set correctly.
I ran into this issue when I mentioned only the DB i wanted to connect to , and my auth db was different (other than admin db ).
The db-name in this line is considered as the auth DB .
new MongoClient("mongodb://username:password#ds011111.mongolab.com:11111/db-name?connect=replicaSet")
Then you can change the selected DB Later
mDb = mClient.GetDatabase(mongoDBName);

Same Error Message but not encountered with a MongoLabs deployment.
I just encountered the same error listed in the title with an Asp.Net Core App. My issue was due to an IOC configuration issue.
In my IOC container, my wrapped MongoClient instance was configured with a dependency transient lifestyle.
Per The MongoDb C# Driver:
It is recommended to store a MongoClient instance in a global place,
either as a static variable or in an IoC container with a singleton
lifetime.
I promoted the lifestyle of my object to a singleton and it resolved the issue.
I am using:
.Net Core 2.0
Mongo C# Driver version 2.5
Castle Windsor for my IOC version 3.3.0
Please reference the C# Driver Client section:
http://mongodb.github.io/mongo-csharp-driver/2.5/reference/driver/connecting/#re-use

Make sure the database username is also case sensitive. I ran into this issue because of case sensitivity of the username.

It's related with MongoDB connection error. Probably you don't have permissions or you didn't specify the allowed IPs in MongoDB. Please check for example in MongoDB Compose if you are able to connect with your MongoDB Atlas. If you won't be able to connect, that means that you have wrong MongoDB connection string.

I had the same issue. I was able to connect to MongoDB Atlas Using MongoDb Compass, but using the same connection string in a C# project I got the error "A timeout occured after 30000ms selecting a server using CompositeServerSelector... ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (61): Connection refused 192.168.1.254:53".
In my case the problem was caused by my Internet provider router. Switching the connection to my iPhone's 4G hotspot solved the connection issue.

The port 10255 was blocked by my Internet provider/firewall rules.
Opening this port at client side fixed the issue.

In my case, while trying to execute the application with docker compose, I forget the environment variables. The problem was resolved by adding the correct environment variables.

I had this issue and turned out the database server was 2 hours behind. Once I fixed its time, the timeout issue was resolved with it.

Related

Docker SQL-Server login problem: AuthenticationException: The remote certificate was rejected by the provided RemoteCertificateValidationCallback

I'm working on a Docker related application, written in C#, based on Entity Framework.
One of the Docker containers, is the ms-sql-server, which is used for database access.
In order to access the SQL-server, following connectionString is created:
Server=ms-sql-server;Initial Catalog=Ownobjects;User ID=SA;Password=some_password
While performing following source code:
public void InitialiseDatabase(IApplicationBuilder app)
{
using (var context = app.ApplicationServices.GetRequiredService<ApplicationDbContext>())
{
context.Database.EnsureCreated();
...
... I get following Exception:
Microsoft.Data.SqlClient.SqlException: 'A connection was successfully established with the server,
but then an error occurred during the pre-login handshake.
(provider: TCP Provider, error: 35 - An internal exception was caught)'
Inner Exception
AuthenticationException: The remote certificate was rejected
by the provided RemoteCertificateValidationCallback.
According to this similar StackOverflow post, two things might not match: the instance name in the connection string and the expected name from the instance.
Is this true? In that case, where or how can I find both names?
If this is not true, then what might be causing this issue?
Edit:
Some further examination:
In the Logs of the ms-sql-server Docker container, I've found following line:
Server name is 'e614890825ac'.
This is an informational message only.
No user action is required
I've used this entry in the connectionString but then the same Exception is raised, but this time with following Inner Exception::
ExtendedSocketException: Resource temporarily unavailable
Edit2:
Again some further examination:
In the meantime I've discovered that my original servername in the connectionString is correct.
Thanks in advance
I've spent some time solving this message SQL Server Pre-Login Handshake
Solution 1 (Encryption in client container):
Dockerfile client (github issue)
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
# ...
# SQL Server trusted connection problem
RUN sed -i 's/CipherString = DEFAULT#SECLEVEL=2/CipherString = DEFAULT#SECLEVEL=1/g' /etc/ssl/openssl.cnf
# ...
Note: There's no need to change your connection string adding Encrypt=false or anything else with this setting
Note 2: I'have tried to use focal and other linux images and only aspnet:6.0 works with this setting.
Solution 2 (Image version or storage problems):
Change the runtime version of the client container (see github comments)
Replace the binding storage or volume in sql server container. This could be a user access problem.
Note: There are some comments about this github issue

MongoDB throwing exception on resolving connection string (C#)

I'm building a winform app that initially connects to a MongoDB server using Driver 2.10.
When I try and connect on my own machine everything works smooth, but when trying to install
clients on other computers via a msi file, the app crashes and I get the following:
ERROR - List of configured name servers must not be empty.
Parameter name: servers
at DnsClient.LookupClient.QueryInternal(DnsQuestion question, DnsQuerySettings queryOptions, IReadOnlyCollection`1 servers)
at DnsClient.LookupClient.Query(DnsQuestion question)
at MongoDB.Driver.Core.Configuration.ConnectionString.Resolve(Boolean resolveHosts)
at MongoDB.Driver.MongoUrl.Resolve(Boolean resolveHosts)
at MongoDB.Driver.MongoClientSettings.FromUrl(MongoUrl url)
at MongoDB.Driver.MongoClient..ctor(String connectionString)
at PaladinFormV2.MongoCRUD..ctor(String i_database)
at PaladinFormV2.Paladin..ctor(Boolean onboarding)
at PaladinFormV2.Program.Main()
I'm connecting through a connection string as follows:
MongoClient client = new MongoClient("mongodb+srv://[name]:[pass]#mcsamples-nwups.mongodb.net/test?retryWrites=true&w=majority");
What am I doing wrong and what information am I missing here to solve this?
Thanks
So after a long time trying to figure out what went wrong here, I came to the conclusion that using the '+srv' inside the connection string tries to resolve the DNS server on which your mongo instance is running, for clients using this it may cause the app to crash.
My fix was using a different connection string that does not use this prefix.
The info on connection string was taken from here https://docs.mongodb.com/manual/reference/connection-string/
Edit your connection string
From
`MongoClient client = new MongoClient("mongodb+srv://[name]:[pass]#mcsamples-nwups.mongodb.net/test?retryWrites=true&w=majority")`
To
`MongoClient client = new MongoClient("mongodb+srv://[name]:[pass]#mcsamples-nwups.mongodb.net/test")`
Also make sure you have internet connection to the cloud server

Connect to Azure Redis Cache via HTTP

I'm using "ServiceStack.Redis" to connect to Redis and it works correctly on my development machine.
Basically, I open the connection via this line:
client = new RedisClient(host);
Where host, on my development machine, is "localhost".
Now, I'd like to upload my application to Azure, so I created a cache in Azure and I'm trying to connect to it by passing the following connection string:
XXX.redis.cache.windows.net,ssl=false,password=YYY
The creation of the "RedisClient" seems to work but when I try to perform an operation (the first one to be executed being client.RemoveByPattern("...")), I get the following error:
Exception Details: System.Net.Sockets.SocketException: No such host is
known
Note that I allowed the cache to be connected to via HTTP, so normally, the port 6379 is unblocked and accessible.
All the example I found over Internet are using "ConnectionMultiplexer" but this class does not seem to be found in the NuGet package "ServiceStack.Redis".
What am I doing wrong?
I was having the same(similar?) issue connecting to Azure Redis with ServiceStack, in the end it was working out the correct syntax for the connection that worked for me. XXX.redis.cache.windows.net?ssl=true
Found some help here https://github.com/ServiceStack/ServiceStack.Redis, but to quote the connection strings section had examples;
"Redis Connection strings have been expanded to support the more versatile URI format which is now able to capture most of Redis Client settings in a single connection string (akin to DB Connection strings).
Redis Connection Strings supports multiple URI-like formats, from a simple hostname or IP Address and port pair to a fully-qualified URI with multiple options specified on the QueryString."
Some examples of supported formats:
localhost
127.0.0.1:6379
redis://localhost:6379
password#localhost:6379
clientid:password#localhost:6379
redis://clientid:password#localhost:6380?ssl=true&db=1
NOTE: I used the final example here but without the redis:// bit as I found this was not needed in Azure.

Endpoint x.x.x.x:port serving hashslot nnnn is not reachable at this point of time

I am using Stackexchange.Redis and trying to connect to a redis cluster and run HashGetAll(). But I'm getting an exception:
Endpoint 172.18.0.2:6379 serving hashslot 4038 is not reachable at this point of time. Please check connectTimeout value. If it is low, try increasing it to give the ConnectionMultiplexer a chance to recover from the network disconnect.
I don't have errors when I work with my cluster via redis-cli.
I am using windows and set up my redis cluster in Docker.
Here is how i connect to my db
var connectionMultiplexer = ConnectionMultiplexer.Connect(new ConfigurationOptions
{
ConnectTimeout = 99000,
EndPoints =
{
"127.0.0.1:6381",
"127.0.0.1:6382",
"127.0.0.1:6383",
"127.0.0.1:6384",
"127.0.0.1:6385",
"127.0.0.1:6386"
}
});
_database = connectionMultiplexer.GetDatabase();
I was trying to restart docker with redis but it did not help.
Then stop problematic node at all, let master to change to another node and application apply change. After a few minutes when the error disappeared I have launched redis again and it started to work again.
I fixed it. I was using multiple containers in my Docker with Redis instances, that I connected into cluster. There was some problem with configuration, I don't know what problem exactly, to fix my problem I used redis-cluster container, that has a pre-configured redis cluster.

ODP.NET ORA-12545: Connect failed because target host or object does not exist

Getting the error ORA-12545: Connect failed because target host or object does not exist when trying to call OracleConnection object's Open Method.
I am able to ping the host. The host is mentioned in tnsora as well. I am able to connect to the same host/db using Toad.
Connections string is: Data
Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=XX.XX.XX.XX)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XXXX)));User
Id=XX_XX;Password=xxxxxx;
Not sure what is the issue here. Please help.
Found Answer at Oracle Connections and VS2012
I was having my project/solution at a Network Drive. When I moved it to local drive, it worked without any issues. :)

Categories

Resources