- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在 Dart 中创建一个后端服务器应用程序,它使用 MySQL 数据库来存储数据。为了进行 SQL 调用,我使用了 SqlJocky 的 ConnectionPool。
应用启动时我做了什么:
在本地,这种方法运行良好。现在我将开发版本推送到 Heroku,几分钟后我遇到了连接问题。
所以我想知道,我是否需要从用于执行查询的池中关闭/释放单个连接?还是查询后的连接重新放入池中免费使用?
所有 MySQL 存储的抽象基类:
abstract class MySQLStore {
MySQLStore(ConnectionPool connectionPool) {
this._connectionPool = connectionPool;
}
ConnectionPool get connectionPool => this._connectionPool;
ConnectionPool _connectionPool;
}
方法getAll的具体实现:
Future<List<T>> getAll() async {
Completer completer = new Completer();
connectionPool.query("SELECT id, name, description FROM role").then((result) {
return result.toList();
}).then((rows) {
completer.complete(this._processRows(rows));
}).catchError((error) {
// TODO: Better error handling.
print(error);
completer.complete(null);
});
return completer.future;
}
我得到的错误:
SocketException: OS Error: Connection timed out, errno = 110, address = ...
最佳答案
这并不能完全回答您的问题,但我认为您可以像这样简化代码:
Future<List<T>> getAll() async {
try {
var result = await connectionPool.query(
"SELECT id, name, description FROM role");
return this._processRows(await result.toList());
} catch(error) {
// TODO: Better error handling.
print(error);
return null;
}
}
我确定这里不需要关闭与query
的连接。不过我不知道prepareExecute
。
根据 SqlJocky 代码中的评论,数据库服务器释放连接可能需要相当长的时间。
也许您需要增加连接池大小(默认为 5),以便在 ConnectionPool
等待释放连接时不会耗尽连接。
关于mysql - SqlJocky 的 ConnectionPool 是否需要关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32045950/
我正在使用 sqljocky 将数据插入 MySQL 数据库。我需要先截断一个表,然后在其中插入多行。我会在单个事务中执行此操作,但 sqljocky 现在似乎根本不支持此操作(或者我可能是 dart
尝试使用 sqljocky 查询 mysql 数据库。此查询在 phpmyadmin 中运行良好,并返回 5 行包含良好数据的结果。在 Dart 中我遇到了异常: Class '_ResultsImp
我目前正在尝试在我的服务器(命令行服务器)和本地主机 xampp mysql 之间设置数据库连接。这是在我的主函数中运行的: main() async { var pool = new Conne
我目前正在构建一个需要将 SQL 数据存储在中央数据库中的 Dart 应用程序。通常我会通过对 PHP 脚本(或 REST 服务)的 ajax 调用来执行此操作。然而,我热衷于将这个项目保留为纯 Da
我正在尝试使用以下代码在Amazon RDS上连接MySQL Server: var pool = new ConnectionPool( host: "xxxx.rds.amazona
我想获取 Dart Server 应用程序中 sqlJocky 提供给我的行数据,并将其(带有列名称)转换为 Map。 IE。 row['email'] == "somename". 行数据是“_Bi
我正在 Dart 中创建一个后端服务器应用程序,它使用 MySQL 数据库来存储数据。为了进行 SQL 调用,我使用了 SqlJocky 的 ConnectionPool。 应用启动时我做了什么: 创
我已经实现了简单的 Web 服务器,使用“sqljocky”包代理 MySQL。我的字符编码有问题,西里尔字母字形显示不正确: ÐавÑдов ÐиÑалий instead of
我似乎无法让 sqljocky + Dart 连接到我的本地 Mariadb(MySQL) 数据库。我可以将 Golang 与 github.com/go-sql-driver/mysql 一起使用,
我正在查看与 MySql 一起使用的 sqljocky,并检查它是如何“工作”的。似乎没有任何“C”代码,它似乎使用套接字。 这样对吗,有知道的人可以为我详细说明一下吗? 最佳答案 我写了 SQLjo
如果我尝试为我的 dart 应用程序提供服务,则会出现以下错误: Serving `web` on http://localhost:80 [INFO] -------------------
所以我有点想使用 Dart 与我的 MySQL 服务器进行交互。我查看了人们是如何做到这一点的,我得到了 sqljocky。现在我在我的主文件中导入 sqljocky,我收到错误:内置库 'dart:
我是一名优秀的程序员,十分优秀!