I was trying to connect to MySQL database in Flutter application using sqljocky5 using the below code using dart language
void getInfo () async {
var pool = new ConnectionPool(
host: 'localhost',
port: 3305,
user: 'root',
password: 'mysql',
db: 'smartlender',
max :5
);
print('test');
var results = await pool.query('SELECT employee.firstName FROM smartlender.employee;'); // exception is thrown here
results.forEach((row){ // for each loop to add data to the list created above
names.add(row[0].toString());
});
Then I received this exception:
I have working connection to MySQL database and the query is exiting without an error .
I appreciate a lot if someone could resolve this issue .
Isn't it default Mysql port number 3306?
Related
I'm new to JavaScript and stuck.
I'm writing my first "real" Electron App and want to connect via sftp. (ssh2-sftp-client to be more specific)
When I set up the connection like the example:
sftp.connect({
host: '192.168.76.173',
port: '22',
username: 'Backup',
password: 'PasswordInPlainText'
}).then(() => {
return sftp.list('/Backups/Server');
}).then(data => {
console.log(data, 'the data info');
}).catch(err => {
console.log(err, 'catch error');
});
everything works like a charm. But when I try to "hide" my credentials in an .env file:
sftp.connect({
host: process.env.HOST,
port: process.env.PORT,
username: process.env.USERNAME,
password: process.env.PASSWORD
}).then(() => {
return sftp.list('/Backups/Server');
}).then(data => {
console.log(data, 'the data info');
}).catch(err => {
console.log(err, 'catch error');
});
I get the error message:
Error: connect: getConnection: All configured authentication methods failed
I checked via
console.log("Host to connect: "+ process.env.HOST)
and the correct output is:
Host to connect: 192.168.76.173
The content of the .env File is
HOST='192.168.76.173'
PORT='22'
USERNAME='Backup'
PASSWORD='PasswordInPlainText'
So this my first time working with environment Variables at all, so I'm guessing I misunderstood something, or a JavaScript property can't be defined by a string this way.
Your problem is that the .env files are not supported in NodeJS by default and you might have some env variables already with the same names and different values (defined in the system probably).
You could either use a NPM package like dotenv or parse the contents of the file by yourself.
You could also test it like that:
// Place this code before you use the ENV variables.
// Replace the `<variables>` with the real data
// and test if your code works with the ENV variables.
process.env.HOST = '<your host ip>';
process.env.PORT = '<your port>';
process.env.USERNAME = '<username>';
process.env.PASSWORD = '<password>';
I've been following this post on Medium to learn how to create and run a dotnet core console app in a docker container, and post to a dotnet core API in another container.
When I run the two applications side-by-side (without docker, i.e. just debugging in vscode), everything works OK - the console app can post to the API. However, when I run the applications in containers using docker-compose up --build, I get an error when the application tries to post to the api:
Unhandled exception. System.AggregateException: One or more errors occurred. (The SSL connection could not be established, see inner exception.)
System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
System.IO.IOException: The handshake failed due to an unexpected packet format.
Searching for solutions to this error hasn't helped much, and I feel that the problem may simply be connectivity between the two containers, but I've had no luck trying to resolve it.
My docker-compose file is as follows:
version: '3.4'
services:
publisher_api:
image: my_publisher_api:latest
container_name: my_publisher_api_container
build:
context: ./publisher_api
dockerfile: Dockerfile
worker:
image: my_worker
container_name: my_worker_container
depends_on:
- "publisher_api"
build:
context: ./worker
dockerfile: Dockerfile
My console app code (or at least the relevant part) is:
public static async Task PostMessage(object postData)
{
var json = JsonConvert.SerializeObject(postData);
var content = new StringContent(json, UnicodeEncoding.UTF8, "application/json");
using (var httpClientHandler = new HttpClientHandler())
{
httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; };
using (var client = new HttpClient(httpClientHandler))
{
var result = await client.PostAsync("https://my_publisher_api_container:80/values", content);
string resultContent = await result.Content.ReadAsStringAsync();
Console.WriteLine($"Server returned {resultContent}");
}
}
}
I wont post any of the API code, as I dont think any of it should be relevant, but please let me know if you think it would help.
If anyone has any idea on what the cause of this error is or how to resolve it, I'd appreciate the help.
Edit
Thought it would be useful to include the versions being used:
dotnet core: 3.0.101
docker: 19.03.5, build 633a0ea838
Looks like I had mad a couple of fairly obvious mistakes, however they're not so obvious when you're completely new to Docker, like me.
The hostname to post to should be the name of the service, not the container.In my case, I had to change the console app to post to the name of the API service declared in the docker-compose file, publisher_api.
Use HTTP instead of HTTPS. When I debugged the API locally, it launches with HTTPS by default. I assumed I would use HTTPS when running the container in docker, but this doesn't seem to work by default. Changing to HTTP resolved the issue (although this ideally will be a short-term solution).
So just for completeness, here's my updated code. Only the URL that the console app posts to had to change:
public static async Task PostMessage(object postData)
{
var json = JsonConvert.SerializeObject(postData);
var content = new StringContent(json, UnicodeEncoding.UTF8, "application/json");
using (var httpClientHandler = new HttpClientHandler())
{
httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; };
using (var client = new HttpClient(httpClientHandler))
{
var result = await client.PostAsync("http://publisher_api80/values", content);
string resultContent = await result.Content.ReadAsStringAsync();
Console.WriteLine($"Server returned {resultContent}");
}
}
}
I was originally on mysql 8.0 which gave me the error
ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
when trying to run my server. I saw on multiple sources that downgrading to mysql#5.7 would solve the problem because 5.7 uses native password authentication, but the same error is still present after downgrading to the earlier version. Are there any other known reasons as to why the error still persists?
Here is my config file:
config.js
// import dependencies
const util = require("util");
const mysql = require("mysql");
// import environment variables
const env = {
env: process.env.NODE_ENV,
host: process.env.DB_HOST,
database: process.env.DB_NAME,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD
}
const database = mysql.createConnection({
host: env.host,
database: env.database,
user: env.user,
password: env.password
});
database.connect(err => {
if (err) {
console.log("Connection " + err);
} else {
console.log(`Connection Success: You are now connected to the ${env.env} database`);
}
});
// promisify all database queries
database.query = util.promisify(database.query);
// export database
module.exports = database;
MySQL 8.0 introduced a default SHA256 encryption that many clients do not understand. You have many options, the easiest being using the older MySQL native password (see https://mysqlserverteam.com/upgrading-to-mysql-8-0-default-authentication-plugin-considerations/) authentication. Change the account to use the older authentication and your client connector will be happy.
I get this error when i try to use the connection
WebSocket connection to 'ws://bolt//localhost:7687' failed: Error in connection establishment: net::ERR_NAME_NOT_RESOLVED
Downloaded neo4j desktop
started the browser and added a local graph database.
Downloaded the js2neo driver
<script src="js/js2neo.min.js"></script>
connected to the database as per http://js2neo.org/
var cx = js2neo.open({ host: "bolt://localhost", user: "neo4j",
password: "1234567890!" })
test the content of the database
cx.run("MATCH (n) RETURN *", { onRecord: console.log })
Your host configuration is not good (it's host not url).
So instead of
var cx = js2neo.open({ host: "bolt://localhost", user: "neo4j",
password: "1234567890!" })
do this :
var cx = js2neo.open({ host: "localhost", user: "neo4j",
password: "1234567890!" })
I'm trying to use Oracle Database Xe on my ruby on rails app
but I'm having a lot of trouble with my database connection I'm currently not sure what the problem is, but according to what I have read I may have a problem with my TNS setup the error message that I'am having is
OCIError: ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
The error appears every time I try to run rake db:migrate
on my rails console I try to run OCI8.new and it gives me this error
OCIError: ORA-12545: Connect failed because target host or object does not exist
I'm pretty much stuck and I'm really not sure what to do here.
TNS:
METRO=
(description=
(address_list=
(address = (protocol = TCP)(host = 127.0.0.1)(port = 1521))
)
(connect_data =
(service_name=METRO)
)
)
Database.yml :
development:
adapter: oracle_enhanced
database: metro
host: 192.168.18.55
username: metro
password: imperium
Looks like you are missing the port in database.yml file.
development:
adapter: oracle_enhanced
host: localhost
port: 1521
database: xe
username: user
password: secret