数据库连接失败,如何重新进行正确配置?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据库连接失败,如何重新进行正确配置?相关的知识,希望对你有一定的参考价值。
参考技术A方法如下:
检查服务是否启动
1、在SQLServer服务器中, 打开SQLServer服务管理器。单击【开始】-【程序】-【Microsoft SQLServer】-【服务管理器】菜单命令。
2、打开【SQLServer服务管理器】,单击【服务器】,选择要检查的SQLServer的实例名【abc10-1DA235E90】,单击【服务】,选择【SQLServer】选项,如果此时暂停或者停止按钮可用,说明服务已经启动;否则则没有启动,启动即可。
3、最好在【SQLServer服务管理器】中将选择随系统启动而启动服务。选择【当启动OS时自动启动服务】选择框,完成让MSSQLSERVER服务随操作系统启动而自动启动。
4、再次打开SQL Server 数据库,选择连接数据库服务器实例,可以正常连接打开数据库了。
5、SQL Server数据库能正常连接得保证网络通畅,操作过程中还需要进行网络测试,可以通过PING命令实现。如下图所示,表示网络通畅。
如何重新连接okhttp-ws
【中文标题】如何重新连接okhttp-ws【英文标题】:How to reconnect okhttp-ws 【发布时间】:2021-10-11 04:21:54 【问题描述】:如果IP地址改变或连接失败,如何正确重新连接?
我正在尝试重新连接 okhttp-ws
.....
@Override
public void onFailure(IOException e, okhttp3.Response response)
try
connecting();
catch (Exception e1)
Timber.e(e1, "onFailure");
@Override
public void onClose(int code, String reason)
Timber.d("Connection unexpectedly closed");
connecting();
public void connecting()
if (wsClient == null)
wsClient = builder.build();
if (call != null) call.cancel();
call = WebSocketCall.create(wsClient, request);
try
lock.lockInterruptibly();
try call.enqueue(listener);
finally
lock.unlock();
catch (InterruptedException e)
Timber.e(e, "connecting error");
我收到一个错误
java.lang.RuntimeException: 无法启动服务...(有 额外):java.util.concurrent.RejectedExecutionException:任务 okhttp3.RealCall$AsyncCall@3f946389 被拒绝 java.util.concurrent.ThreadPoolExecutor@d784f8e[终止,池大小 = 0,活动线程 = 0,排队任务 = 0,已完成任务 = 1] 在 android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3320)
【问题讨论】:
【参考方案1】:看例子和我的简单library
...
try
WebsocketClient.dispatcher().cancelAll();// to cancel all requests
...
在失败时触发 ( ... ) 您可以重新连接
【讨论】:
【参考方案2】: /**
* Configure this client to retry or not when a connectivity problem is encountered. By default,
* this client silently recovers from the following problems:
*
* <ul>
* <li><strong>Unreachable IP addresses.</strong> If the URL's host has multiple IP addresses,
* failure to reach any individual IP address doesn't fail the overall request. This can
* increase availability of multi-homed services.
* <li><strong>Stale pooled connections.</strong> The @link ConnectionPool reuses sockets
* to decrease request latency, but these connections will occasionally time out.
* <li><strong>Unreachable proxy servers.</strong> A @link ProxySelector can be used to
* attempt multiple proxy servers in sequence, eventually falling back to a direct
* connection.
* </ul>
*
* Set this to false to avoid retrying requests when doing so is destructive. In this case the
* calling application should do its own recovery of connectivity failures.
*/
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.retryOnConnectionFailure(true);
【讨论】:
我试过这个用于网络套接字,不幸的是它没有重新连接网络套接字以上是关于数据库连接失败,如何重新进行正确配置?的主要内容,如果未能解决你的问题,请参考以下文章