How connect C# to Postgresql in host j.layershift.co.uk - c#

I have installed postgresql database in http://postgres-project-1241043.j.layershift.co.uk/ host.
I want to connect to the database using C#. I use Npgsql with following connection string.
connectionString = # "Server = postgres-project-1241043.j.layershift.co.uk, Port = 5432, User Id = postgre; Password = abcdef; Database = dbluanvantn;";
But I am not able to connect to the server and get error:
Npgsql.NpgsqlException: Failed to a connection to
'postgres-project1241043.j.layershift.co.uk'.
Am I using correct connection string?. Help me fix it.

You can only connect to Postgres (on our Jelastic service) if you add a public IP to the node first. Without that step, you can only connect to it locally (i.e. from another server within your Jelastic environment).
Also I want to mention that you are always welcome to contact our support team (our tech. support is 24x7 and completely free; even for our trial accounts) if you need any further help.

Related

ADO.NET FirebirdSql.Data.FirebirdClient.FbException: "Unable to complete network request to host "

I have a pretty strange problem when trying to connect my C# program to an existing Firebird server.
First of all, this is reproducable with the default connection example from the Firebird documentation at https://github.com/FirebirdSQL/NETProvider/blob/master/Provider/docs/ado-net.md
using (var connection = new FBConnection("database=192.168.0.150:c:\\Data\\demo.fdb;user=sysdba;password=m#sterkey"))
{
connection.Open();
using (var transaction = connection.BeginTransaction())
{
using (var command = new FbCommand("select * from demo", connection, transaction))
{
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
var values = new object[reader.FieldCount];
reader.GetValues(values);
Console.WriteLine(string.Join("|", values));
}
}
}
}
}
It all works fine when I am on my machine, I also can connect to a Firebird server on my coworkers PC.
But I cannot connect to the Firebird server on my other development server. I found an answer in another question and want to tell you that the server does not have internet access.
https://stackoverflow.com/a/57569057/2785084
This is the exception I get:
FirebirdSql.Data.FirebirdClient.FbException: "Unable to complete
network request to host " No message for error code 335544721 found."
IscException: Unable to complete network request to host " No message
for error code 335544721 found. IOException: Unable to read data from
the transport connection: An existing connection was forcibly closed
by the remote host
I already updated to the latest stable Version of Firebird. I can guarantee that the server is running and no firewall is blocking my connection, because when I try to connect with our old Delphi program, everything works. I also can connect using the lightweight Firebird management tool Flamerobin from Flamerobin.org, which is written in C++, I think.
When I try to connect with DBeaver I get the following message:
[SQLState:28000, ISC error code:335544472] Your user name and
password are not defined. Ask your database administrator to set up a
Firebird login.
I'm pretty sure that the user and password are correct. I do not use the default password, but a password with an # sign in it, maybe it has something to do with that.
I now have 2 programs that can Connect (Delphi and C++), and two that cannot connect (C# and Java). Does anyone have any clue or tweak how to change the connection that I can connect to the server?
Thanks to Mark Rotteveel for the comment which got me to the solution.
I can connect with the default password "masterkey", so it is obvious that the srp user was created with the default credentials and therefore a connection with the other credentials is not possible.
I have to correct the users in my old server.
Thanks for the hint that ADO.NET only supports srp.

How do I connect to my Google cloud SQL instance with C#?

I am trying to use visual studio to write a program in c# and have it connect to my google cloud sql server. Unfortunately I have been trying to troubleshoot it and have had no luck. I already added my IP and my connection works through MYSQL Workbench.
I attempted to connect with the whole data source, network library, initial catalog, etc. I tried it without the network library and used the proper way to escape \ in the string during the connection. I also tried the default 1433 port and 3306. No luck.
// Build Connection String
SqlConnection clearviscon = new SqlConnection(#"Server=xx.xx.xx.xx\alpine-park-243102:us-central1:xxx, 3306;Network Library=DBMSSOCN;Initial Catalog=xxdatabase;User ID=root;Password=xxx123");
clearviscon.Open();
To connect to Google Cloud SQL for MySQL, you must use a MySQL client library. I recommend MySqlConnector.
Your connection string will be Server=xx.xx.xx.xx;Database=xxdatabase;User ID=root;Password=xxx123.
If you're using a client SSL certificate to connect to your server, add this to the end of your connection string: ;SslCa=server-ca.pem;SslCert=client-cert.pem;SslKey=client-key.pem.
You must use MySqlConnection.
See this link for more information: https://cloud.google.com/dotnet/docs/getting-started/using-cloud-sql

MySQL Server - Remote Access - "Unable to connect to any of the specified MySQL hosts"

I've built a C#-application and now I want to connect that application with an MySQL-Server that is running in my local network.
For this purpose I used the MySQL-connector like the following:
string connectionString = "server=192.168.0.11;uid=User1;pwd=PWD1234;database=Caller;";
MySqlConnection conn = new MySqlConnection(connectionString);
conn.Open();
But everytime I want to connect to the database and open the connection, it fails with the error "Unable to connect to any of the specified MySQL hosts.".
I've tried a couple of different things:
Granted all privileges on the user
GRANT ALL PRIVILEGES ON . TO 'User1'#'%' IDENTIFIED BY 'PWD1234' WITH GRANT OPTION; FLUSH PRIVILEGES;
Changed the MySQL-configuration file
Now it doesn't contain a line like bind-adress or skip-networking anymore.
Restarted the MySQL server
So where is the problem? I am not able to figure it out...
The server is running on Ubuntu Server, actual version.
Thank you and with best regards,
Nicolas

.NET C# - Cannot access a SQL Server database behind remote machine

I have the credentials to access a server in a local network - a network that is behind a proxy. And that server is running a SQL Server 7.0 database. The database is configured to use Windows authentication for log in.
I use the Remote Desktop Connection to access the server, put in the credentials, and when inside I open the Query Analyser, select log in with Windows authentication and then I query the DB.
But, now I need a .NET C# program to access the database from my machine, remotely. I have checked for a TCP/IP connection on port 1433 and it's open. However, with the following code, I cannot open a connection to the remote database.
SqlConnectionStringBuilder connStringBuilder = new SqlConnectionStringBuilder();
connStringBuilder["Trusted_Connection"] = false;
connStringBuilder["user id"] = "<domain>\\<user>";
connStringBuilder["password"] = "<pass>";
connStringBuilder["Database"] = "<db>";
connStringBuilder["Server"] = "\\\\<servername>\\MSSQLServer,1433";
connStringBuilder["Connection Timeout"] = "30";
SqlConnection myConn = new SqlConnection(connStringBuilder.ConnectionString);
try
{
myConn.Open();
// success
Console.WriteLine("Connection Opened");
}
catch (Exception e)
{
// failed
Console.WriteLine("Connection Failed");
Console.WriteLine(e.ToString());
}
The servername field is the same text I put in the Remote Desktop Connection tool, as it is with the user id and password fields after a connection is established (normal log on with Windows Server 2000).
Also, with the SSMS (SQL Server Management Studio) I cannot connect to the instance, however with Windows Explorer I can browse the server's drives with \\servername\e$ (for example).
Thank you in advance!
EDIT 1
I believe the problem is go through the remote machine log in, but I have no idea how to do that. I tested on a local db on my machine and the program works like a charm.
The error message from the exception e is the following, weather with true or false on the Trusted Connection:
System.Data.SqlClient.SqlException: A network-related or instance-specific error
occurred while establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that SQL Server is
configured to allow remote connections. (provider: SQL Network Interface, error: 25 -
Connection string is not valid)
at .... etc
EDIT 2
The steps I take to log on to the machine using some credentials are the following:
I first put in the server name as in "MACHINE33" (without quotes)
Remote Desktop Connection
And then I put the credentials \ as in "me\johndoe"
Credentials to access the remote machine
In the end the database is accessed using the windows authentication used to access the machine.
If you are using integrated authentication then the value for trusted connection should be either 'true' or 'sspi', not false. If 'true', any user id and password you specify on the connection string will be ignored so might as well not set them if you are intending to use the credentials for the currently logged in user (or the AppPool user if a web app, or the service user if a windows service etc.).
Are you using a named SQL Server instance? If so, a dynamic port is used, not 1433. You would need to either configure SQL Server to use a specific port for the named instance, or not specify a port.
"Login failed for user" when specifying default port
I have asked the systems administrator, this morning, and he told me that the database cannot be accessed from the outside, even though there is a TCP/IP configuration on port 1433 (checked under Server Network Utility for SQL Server 7.0). The reason is that the whole network is behind a proxy that checks all incoming requests and prevents the ones not coming from the tools specified (i.e. Remote Desktop Connection).
Since what I want is to migrate some fields from the structure of the old database to a new one, used by a new system, the solution is:
Access the remote machine, create a backup of the database, access the files through mapping the network drive, copy the backup files to your machine, create a local database and restore the backup to your new local database.
It's not the most elegant way, but it's the only way. And as an advice, first ask the systems administrator if you're behind a network full of proxies because it can save you a lot of headaches.
Thank you and sorry for the whole trouble.

connect mysql with c#

I'm building a c# windows application which will connect with the mysql database in a remote server.
I'm using the following connect script
string connectionString;
connectionString = "SERVER = eu5.org;UID = myuserid; PASSWORD = mypassword; DATABASE = mydatabasename;";
connection = new MySqlConnection(connectionString);
It shows the error couldn't connect to the database.
P.S: Mysql database is at eu5.org server
Personally I prefer to use the MySql Workbench IDE for testing connections and working (Querying) the database directly where possible. Most hosted databases that I have worked with normally define the Server as Instance.[DomainName] so I would have expected your server URL to be something like MySql1.eu5.org
Below is a connection string that I tested using the MySql Connector, change the parameters.
<connectionStrings>
<add name="MySqlConnection" connectionString="server=INSTANCENAME.DOMAINNAME.COM;UID=USERNAME;password=PASSWORD;database=DATABASENAME;Persist Security Info=True;" providerName="MySql.Data.MySqlClient"/>
MAke sure that your server should be started...
Just read the FAQ:
Many people want to only use database, but their site is hosted elsewhere. We provide free database for websites hosted with us. For that reason, external access is blocked without exception.
--> http://www.freewebhostingarea.com/faq.html
so it's not possible to access your MySQL-DB from external sources.
only localhost will be allowed
Your code is correct.
Use a browser for MySQL, like http://mysql-query-browser-for-windows.apponic.com/ to check if your database is available.

Categories