У меня проблемы с подключением к базе данных SQL Server, которую я создал в своем ПК для небольшого приложения. Сервер называется «InspironN5110-D». Я использую аутентификацию Windows для входа на сервер. Уже загрузил драйвер из Microsoft и скопировал его контент в папку программных файлов и добавил путь (C: \ Program Files \ Microsoft JDBC Driver 4.0 для SQL Server \ SQLJDBC_4.0 \ ENU \ SQLJDBC4.JAR) к переменной PATH и ClassPath (не уверен, какой из них использовать) и все еще получить эту ошибку.Creating Connection.
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host INSPIRONN5110-D, port 1433 has failed. Error: "connect timed out. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
.....
< /code>
Вот метод, в котором я пытаюсь подключиться к базе данных. < /p>
private Connection connectToDB() {
String connectionUrl = "jdbc:sqlserver://INSPIRONN5110-D; databaseName=MemoryHelp;";
Connection con = null;
try{
// Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.println("Creating Connection.");
con = DriverManager.getConnection(connectionUrl);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
// } catch (ClassNotFoundException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
} finally{
System.out.println("Connection created.");
}
return con;
}
< /code>
Пробое изменить URL -адрес подключения на "jdbc: sqlserver: // localhost; databaseName = memoryHelp;" < /p>
Получение этой ошибки сейчас: < /p>
Creating Connection.
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
....
< /code>
Наконец -то решил его. Пришлось перейти к SQL Server Configuration Manager и включить подключения TCP /IP на сервер, затем скопируйте файл SQLJDBC_AUTH.DLL из папки драйвера в папку System32 и использование следующего URL -адреса подключения может заставить его работать: < /p>
String connectionUrl = "jdbc:sqlserver://localhost;databaseName=MemoryHelp;integratedSecurity=true";
Подробнее здесь: https://stackoverflow.com/questions/257 ... ection-url