java and access error when connecting to the database - java

Today I encountered the following problem. When connecting to a database, the following error.Appeal to the remote database by connecting through vpn.
Added necessary firewall ports and even tried to disconnect its(did not help)
Added record to $JAVA_HOME/jre/lib/security/java.policy
grant codeBase "file:/-" {
permission java.security.AllPermission;
};(did not help)
If trying to connect with same data through sql management studio, it works and there is access. from the development environment no connection
Example(string connection = jdbc:sqlserver://DEVMSSQL14.test.com:1433;SCHEMA=test;DATABASENAME=test, sql managment studia = DEVMSSQL14.test.com,1433)
on another computer it works without problems, the same version of the project
It remains only to "Permission denied: connect".Maybe somebody faced with similar
Error:
The TCP/IP connection to the host DEVMSSQL14.test.com, port 1433 has failed. Error: "Permission denied: 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.".

In the error message, you have shown like DEVMSSQL14.test.com, 1433 has failed.
I believe, it is correct. I dont think. this host name is correct. which says "TEST" as domain
Open the cmd, try to ping DEVMSSQL14.test.com
Success case :
If you are able to ping, then make sure the services are running for sql in services
Failure case:
Get the right host name to establish the connection
When i tried, i got this message, because i may be out of network.
Pinging DEVMSSQL14.test.com [208.64.121.161] with 32 bytes of data:
Request timed out.
Request timed out.

Try setting a System Property while running the code.
The catch is to introduce this line in code: System.setProperty("java.net.preferIPv4Stack", "true");
Or to pass it in VM option: -Djava.net.preferIPv4Stack=true

Related

Netbeans Connection to SQLSERVER still not wroking

I am still facing this problem for about 2 days already. It seems I did some researched on Google and as well stack overflow. I followed step by step but still not running.
-> Enable SQL BROWSER
-> Enable TCP/IP PORT and change to 1433
I tried both but still not working. It still giving me this error.
Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: The connection to the host ., named instance sqlexpress has failed. Error: "java.net.UnknownHostException: .". Verify the server and instance names, check that no firewall is blocking UDP traffic to port 1434, and for SQL Server 2005 or later verify that the SQL Server Browser Service is running on the host.
This is my connection code:
Connection conn = DriverManager.getConnection("jdbc:sqlserver://.\\sqlexpress;user=sa;password=;database=pharmacy_posic");
My server name: .\sqlexpress
My Username : sa
My password : (blank)
Am I making any mistake on the connection?
Check this it is explained very well:
https://www.youtube.com/watch?v=Z46OHxdEEEI

Issues with connecting to sql server db via linux

Im trying to execute a jar file from linux.The jar contains java code for connecting to sql server. When I try to execute the jar, Im getting the below error
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host servername, port 1433 has failed. Error: "null. 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.".
The connect properties file seems to have a valid username/password. I have checked the sql server configuration manager and the TCP/IP protocol is enabled. Im able to execute the same jar file in winodws and the sql server connection is established fine without any issues. Please let me know the steps I have to take to get this issue resolved.
Any help on this is much appreciated. Thanks

SQLServer - SQLServerException with jdbc access

I have installed on my pc ms sqlserver express 2012, I am trying to reach it via jdbc but I am not successfull, I get the error:
com.microsoft.sqlserver.jdbc.SQLServerException: 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
I am accessing via the following url: "jdbc:sqlserver://localhost:1433;database=mytest;"
I enabled the tcp/ip via the Sql server configuration manager, but if I run netstat-an I can't see the 1433 port listening.
I disabled windows firewall too...
I am lost :(
Any help?
Thank you!
****UPDATE**
I could overcome the problem by enabling port 1433 on IpAll under Sql Server configuration manager - Sql Server Network configuration - Protocols for SQLEXPRESS - tcp-ip Properties - Ip Addresses. But now I get another error:com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'sa'. ClientConnectionId
Any ideas? thanks!
The answer for the error:
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'sa'. ClientConnectionId
is:
Go to Object explorer, click on properties (right click on Sql Server name), and on the security tab click on Sql Server and Windows authentication mode.
This worked for me.

Connecting to external database through telnet

I have a java program that connects to a MS SQL database. The program works perfectly when running through eclipse however I get an error when I run it through AIX:
java.sql.SQLException: Network error IOException: A remote host refused an attempted connect operation.
I can successfully ping the server but am not able to telnet into the server. I am also not able to telnet from my windows desktop.
I am using jtds to connect:
String connectionString = "jdbc:jtds:sqlserver://"+dropez_ip_address+"/"+dropez_db_name;
ResultSet rs = null;
Statement stmt = null;
try{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection conn = DriverManager.getConnection(connectionString, dropez_db_username, dropez_db_password);
stmt = conn.createStatement();
}catch(Exception e){}
Here is some documentation from jTDS regarding the issue, but I am still not able to resolve the issue.
Why do I get java.sql.SQLException: "Network error IOException: Connection refused: connect" when trying to get a connection?
The "Connection refused" exception is thrown by jTDS when it is unable to connect to the server. There may be a number of reasons why this could happen:
- The server name is misspelled or the port number is incorrect.
- SQL Server is not configured to use TCP/IP. Either enable TCP/IP from SQL Server's Network Utility app or have jTDS connect via named pipes (see the URL format for information on how to do this).
- There is a firewall blocking port 1433 on the server.
To check whether TCP/IP is enabled and the port is not blocked you can use "telnet 1433". Until telnet doesn't connect, jTDS won't either. If you can't figure out why, ask your network administrator for help.
If you can't telnet on port 1433, you are blocked by a firewall somewhere in the middle between your machine and the server. That's not a java related problem.
May it be that when you say "it runs perfectly under eclipse but not AIX" you are taking about 2 different computers ? If so, the one with eclipse is not firewalled, the one where you deploy your app is blocked.
But again, nothing to do with java. It's a level 3 error (TCP layer) of TCP-IP model.
Regards,
Stéphane
Your SQL Server database probably doesn't have the TCP/IP protocol enabled, to enable it:
From the Microsoft SQL Server 2005 -> Configuration Tools, open the 'Microsoft SQL Server Configuration Manager'.
Expand ‘SQL Server 2005 Network Configuration’, and then click ‘Protocols for ’.
Right-click ‘TCP/IP’ and then click ‘Enable’. The icon for the protocol will change to show that the protocol is enabled.
For SQL Server 2008:

java to sql server connectivity exception

I have this error/exception-
SQL Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "connect timed out. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.".
and my code is-
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://localhost:1433";
Connection con = DriverManager.getConnection(connectionUrl,"","");
System.out.println("ok");
} catch (SQLException e) {
System.out.println("SQL Exception: "+ e.toString());
}
catch (ClassNotFoundException cE) {
System.out.println("Class Not Found Exception: "+ cE.toString());
}
how can i sovle it,please help me.
This could mean almost anything - basically, it was impossible to connect to port 1433 on localhost. Could be a network problem, could be that the database is not started, could be that it is running but not bound to port 1433.
In a pinch, you can always open a shell and run
telnet localhost 1433
to see if it is possible to make a connection at all.
I had this error.
I fixed it by going into the SQL Server Configuration Manager.
Under SQL Server 2005 Configuration -> Protocols for SQLEXPRESS. Look at the IP Address tab of the Properties of the TCP/IP Protocol.
At the very bottom of the protocol list (under IPALL), the TCP Port field was blank. I put 1433 there, saved, restarted the SQL service and it worked great :)
It's telling you it can't connect.
Check that sql server is available on your local machine on that port.
Check that sql server is accepting connections with the blank name and password you're providing in your getConnection() invocation.
Check that your jdbc url is in the correct form, they're sometimes manufacturer/driver specific.
The error just means that java was not able to connect to your database. Either database is not running or your firewall is blocking connections to it. If you are sure your DB server is up on your localhost, try after disabling your windows firewall.
Lets look at some of the possibilities:
The database server is not listening on localhost:1433 : you probably would get a "connection refused" rather than a "connection timed out"
The database server is catatonic (i.e. in a state where it is not responding to requests) : you could get a "connection timed out".
The database server is massively overloaded : you could get a "connection timed out", but you would probably notice that the machine was very slow.
The local software firewall is configured to block all requests to port 1433 : you could get either "connection refused" or "connection timed out" ... or some other response. (It depends exactly what the firewall does with unwanted traffic.)
The loopback interface (for IP 127.0.0.x) is not configured : you are more likely to get "no route to host" or "no route to network".
The DNS entry for localhost is misconfigured (i.e. localhost doesn't resolve to 127.0.0.x) - lots of things could happen ... depending on how it is misconfigured.
Here are some things you could do to diagnose the problem ... depending on your system:
Look at the configured networks using ipconfig or ifconfig.
Look at "/etc/hosts" to check the entry for localhost
Try to connect to the service using telnet -p 1433
Use "ps" or the task manager to see what processes are running.
Check the local firewall configs to ensure that 1433 is open for (at least) TCP from the configured localhost IP address (probably 127.0.0.1).
I had a problem similar to this, and solved it by adding the line:
System.setProperty("java.net.preferIPv4Stack", "true");
The problem was it used IPv6 instead of IPv4 to access the db host (I used it for a DB on a remote host, not localhost).
Hope it helps.

Categories

Resources