我尝试保持与本地 SQL 服务器的多个连接。我编写了一个简单的程序来实现这一点,它在我的服务器(SQL server 2008 R2)上运行良好。但是,当我尝试在我的 PC (SQL server 2012) 上执行相同的程序时,尝试启动第二个连接时出现执行异常。
这是失败的程序:
public static Connection getUpdateDbConnection()
{
Connection conn=null;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
JDBCuRL="jdbc:sqlserver://localhost\\SQL2012EITAJE:58704;user=***;password=***
conn = DriverManager.getConnection(jdbcUrl)
conn.setReadOnly(false);
}
catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
public static void main(...){
...
Connection con1 = getUpdateDbConnection(); <-- executes fine
Connection con2 = getUpdateDbConnection(); <-- fails here
...
}
这是抛出的异常:
WARNING: ConnectionID:2 Prelogin error: host localhost port 58704 Error reading prelogin response: Connection reset
com.microsoft.sqlserver.jdbc.SQLServerException: Connection reset
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1509)
at com.microsoft.sqlserver.jdbc.TDSChannel.read(IOBuffer.java:1547)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.Prelogin(SQLServerConnection.java:1279)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1200)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(SQLServerConnection.java:1054)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:758)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:842)*
我在“SQL Server Management Studio”中增加了允许的连接数并重新启动了 SQL 服务,但并没有解决问题。知道如何解决这个问题吗?谢谢