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 am currently working on a project with someone. We are connecting to a oracle Database using the NuGet Package Oracle.ManagedDataAccess.Core.
We are connecting using a connection string that looks like this:
"User Id={this._dbUser};Password={this._dbPassword};Data Source={this._dbServer};"
The Parameters we pass on are correct we checked multiple times.
At first I got a Connection Timed out error which we fixed by adding persist security info=false;Connection Timeout=120; to the connection string.
At first it seemed to be working but then we encountered a new error.
This time it was saying:
Oracle communication: Connection to server could not be established or connection string not parsed
(Might not be 100% accurate because I had to translate it from German to English)
We could not find a solution for this error but we discovered that the error only gets thrown when we run the code on my machine. His is doing totally fine and can connect without any problems.
Could it be that I have some settings set on my machine that would prevent me from accessing the Database?
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.
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