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
Related
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
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.
here is all info.
Step 1
Step 2- Error Msg
Step 3- connection String
I have tried without using port number but the problem is same. There is IP restrictions for remote login. but if it is because of IP restriction why am I able to connect with Navicat.
Code of C# where i'm getting error.
As per step 1 it seems the connection has been successfully established, but still you are unable to connect to the specific database. Check the name of the database or confirm that the database exists with the name supplied in the connection string. You can do that even by creating a connection from Navicat. If the database exists you will find it there.
Cheers
Maybe you should invoke mysqlcon.Open() before using mysqlcon.
I am creating desktop application in c# but i wont to use Online Database created in mysql.
String mysqlConnectionString = "Server=216.14.120.105;Database=xxx_keys;UID=xxx_root;Password=xxx;Port=3306";
MySqlConnection connection = new MySqlConnection(mysqlConnectionString);
connection.Open();
this is the code i am using but i got an error unable to access host.
where i am wrong and if you have any proper code or details then give me.
If this is a MySQL database in local server user "localhost" for server IP as georgi-it also told. But if this is an external database first try to open a telnet connection on dos-prompt to see if there is some firewall block or something like that:
telnet 216.14.120.105 3306
if you don't get an error message and see a blank page then it means you can reach mysql server
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