Как установить URL-адрес подключения к SQL-серверу?JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Как установить URL-адрес подключения к SQL-серверу?

Сообщение Anonymous »

У меня возникли проблемы с подключением к базе данных SQL Server, которую я создал на своем компьютере для небольшого приложения. Сервер называется «INSPIRONN5110-D». Я использую аутентификацию Windows для входа на сервер. Уже скачал драйвер от Microsoft, скопировал его содержимое в папку Program Files и добавил путь (C:\Program Files\Microsoft JDBC Driver 4.0 for SQL Server\sqljdbc_4.0\enu\sqljdbc4.jar) к пути и переменной пути к классам (не уверен, какой из них использовать), но все равно получаю эту ошибку.

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.".
.....


Вот метод, с помощью которого я пытаюсь подключиться к базе данных.

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;
}


Пытался изменить URL-адрес подключения на «jdbc:sqlserver://localhost; dataName=MemoryHelp;»

Получаю эту ошибку:

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.".
....


Наконец-то решил проблему. Пришлось зайти в диспетчер конфигурации SQL Server и включить соединения TCP/IP с сервером, затем скопировать файл sqljdbc_auth.dll из папки драйвера в папку system32 и использовать следующий URL-адрес подключения, чтобы заставить его работать:

String connectionUrl = "jdbc:sqlserver://localhost;databaseName=MemoryHelp;integratedSecurity=true";


Подробнее здесь: https://stackoverflow.com/questions/257 ... ection-url
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»