-
-
Notifications
You must be signed in to change notification settings - Fork 541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
maybe should return a error detail for connection failure #310
Comments
Hey @yamowner, welcome!! Can you show me how you setup the connection? Remember to mask the credentials in connection string. |
It should be something like... let db: DatabaseConnection = Database::connect("mysql://username:password@host/database").await?; |
@billy1624 yes, i did like this: async fn main() {
let conn_str = "mysql://username:password@host:port/test";
match connect_db(conn_str).await {
Ok(db) => {
let admin = Account::find_by_id(1).one(&db).await.unwrap();
println!("{:#?}", &admin);
}
Err(err) => {
println!("{}", &err);
}
}
}
async fn connect_db(conn_str: &str) -> Result<DatabaseConnection, DbErr> {
let mut opt = ConnectOptions::new(conn_str.to_owned());
opt.max_connections(10)
.min_connections(5)
.connect_timeout(Duration::from_secs(8))
.idle_timeout(Duration::from_secs(8));
let db = Database::connect(opt).await;
db
} then, it print "Connection Error: Failed to connect.", this mistake confused me。thanks for your reply ^_^ |
my Cargo.toml like this: [dependencies]
sea-orm = { version = "^0", features = [
"sqlx-mysql",
"runtime-tokio-rustls", // it's ok when change to runtime-tokio-native-tls
"macros",
"debug-print",
], default-features = false }
chrono = "*"
tokio = { version = "1", features = ["full"] } |
Hmmmm... this is weird |
I can't reproduce the error in #311 |
Hey @yamowner, can you try #312? And see what error thrown out of SQLx [dependencies]
sea-orm = { version = "^0", git="https://github.com/SeaQL/sea-orm.git", branch = "detailed-conn-errors", features = [
"sqlx-mysql",
"runtime-tokio-rustls",
"macros",
"debug-print",
], default-features = false }
|
@billy1624 I found answer in this sqlx issue#846, it looks like to be rustls lack support of ipaddress. my error detail is this: error occurred while attempting to establish a TLS connection: InvalidDNSNameError |
Oh, interesting issue |
i edit my /etc/hosts, and change my connect string, then it works~ |
Crazy... then you have to convert your address to IPv6 and quote it loll |
Anyways, we will improve the error messages #312 |
Thank you for your kind help!!, next time i'll provide more useful information |
Welcome! |
I am a beginner, when i use sea-orm with mysql, The first problem I encountered was the connection problem, it only told me: "Connection Error: Failed to connect". I am very confused. em.. maybe we can return error detail for fix code.
The text was updated successfully, but these errors were encountered: