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.
Related
I'm trying to connect to a Heroku PostgreSQL instance using the npgsql NuGet package. I've a problem with the connection string – the hostname gets replaced with my computer's public IP (see the screenshot below). An exception gets thrown in the Open() method of the NpgsqlConnection stating that the host doesn't exist. The rest of the parameters specified in the string (username, password and the database used) get recognized correctly.
I've tried using Host, Server and server instead of host but that doesn't seem to change anything. The database is up and running as I can connect to it using DataGrip with the same connection details.
Thanks!
The error you are seeing is from the database, not the library. It is saying that pg_hga.conf doesn't have an entry to allow your ip address to have access. You can read more about this file here:
https://www.postgresql.org/docs/current/auth-pg-hba-conf.html
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
We have a big system with bunch of services communicating with each other via TIBCO EMS Messaging.
Now, one of the services keeps throwing this exception when it tries to connect to EMS server:
TIBCO.EMS.IllegalStateException: connect failed: server in standby mode
However, other services on the same EMS server are working just fine without any exception.
I tried to reproduce this by creating a console application which would use same credentials to connect to EMS server on the same destination (Queue) but couldn't reproduce this error.
EMS connection is fault-tolerant and it might have been failed over to secondary server, however, now I see primary server is back up.
I also tried to connect to primary server only (which I can see is up & running) but it fails with the same exception.
Below is the stack trace for reference:
TIBCO.EMS.IllegalStateException: connect failed: server in standby mode
at TIBCO.EMS.CFImpl._CreateConnection(String userName, String password, Boolean xa)
at TIBCO.EMS.ConnectionFactory.CreateConnection(String userName, String password)
at Ems.makeConn()
We're using TIBCO.EMS.dll v. 8.1.0.10 on .NET 4.0.
Any idea what can cause this exception ?
Could your connection string only mention one of the hosts inside an FT/HA setup ? This looks like the error message returned when you are trying to connect to only one of the HA/FT host, but not the one active at the moment.
If it is the case, the connection string will work most of the time, but a proper EMS HA connection string include two (or more!) EMS host and port. Only one is active at the same time.
It typically looks like this:
serverUrl=tcp://server0:7222, tcp://server1:7344
See source doc here in TIBCO docs.
It turned out tools we were using to check if server is active (we don't have admin rights on the servers) was misbehaving (showing incorrect status), so none of those servers were really active (not primary nor secondary).
As soon as server was brought up this error message went away.
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.
What connection string should I use if SSMS connects to it using simply machine name, without instance name?
I mean it connects using the following string: PCName
I used to connect using PCName/SQLExpress. I cannot set correct connection string in my app in order to connect app to database on this machine.
How can I check what data source I should use? I've checked in Sql Server configuration that server instance named as SQLEXPRESS.
So I tried data source as:
.\SQLEXPRESS
PCName\SQLEXPRESS
.
I'm trying to connect to a service-based database, located in my app folder. So I'm using the following connection string:
data source=PCName;attachdbfilename=|DataDirectory|\spareparts.mdf;integrated security=true;user instance=true;multipleactiveresultsets=true;App=EntityFramework;
If SSMS connects via PCName then your application should be able to use Data Source=PCName. However it depends on whether your application is on the same machine as SSMS or not. If on a different machine it might not be able to connect for a variety of reasons. We can't speculate what the problem might be if all you do to describe the issue is "It won't connect" - what does that mean? Do you get an error message? If so, what is it? Make sure:
SQL Browser service is started
TCP/IP is enabled
Add Network=DBMSSOCN; to the connection string
You've also tried the IP address in addition to PCName
Firewall isn't blocking the SQL Server port