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

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

Сообщение Anonymous »


I'm having problems connecting to a SQL Server database I created in my pc for a small app. The server's called 'INSPIRONN5110-D'. I use Windows Authentication to login to the server. Already downloaded the driver from microsoft and copied its content to the program files folder and added the path (C:\Program Files\Microsoft JDBC Driver 4.0 for SQL Server\sqljdbc_4.0\enu\sqljdbc4.jar) to the path and classpath variable (not sure which one to use) and still get this error.

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.". ..... Here's the method where I try to connect to the data base.

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; } Tried changing the connection url to "jdbc:sqlserver://localhost; databaseName=MemoryHelp;"

Getting this error now:

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.". .... Finally solved it. Had to go to SQL Server Configuration Manager and enable tcp/ip connections to the server, then copy the sqljdbc_auth.dll file from the driver's folder to the system32 folder and using the following connection URL could get it to work:
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»