Netbeans Connection to SQLSERVER still not wroking - java

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

Related

Unable to connect to a Oracle db from Linux machine in java

I have registered a Linux machine as runner in my gitlab and tried to execute my scripts there.
While executing I got an error for database connection
Issue : java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
When I connect from my local machine (Windows 7 & 10) it is working fine.
Attempts:
Tried to connect using jtds but I'm getting some other unknown issue.
Checked few other answers and they have provided that it could be because of firewall enabled but since we did not have full access to that db server , I could not disable and check.(Could this be the issue?)
My Connection code :
ConURL = "jdbc:oracle:thin:#" + ConstructSQLConnectionURL(host,sid,port);
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(ConURL, dbUserName, dbPassword);
I am stuck with this issue and blocked from executing pipeline.
Can anyone let me know what could be the possible reason for this and help me with this?
Thanks in advance
It appears to be a network connectivity issue. I'd start with local firewalls on each system. Can you ping the database from the client? If not, look for network routing or firewall blockers. Also look at host-based firewalls, or confirm with the DBA whether there is something like valid node checking in place to limit database clients.

Trouble connecting to SQL server using Java

This is what I've written as part of my code:
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String host1 = "<URL/Connection path string>";
String uname1= "<User name>";
String pwd1 = "<Password>";
Connection con1 =DriverManager.getConnection(host1,uname1,pwd1);
Statement stmt1 = con1.createStatement();
ResultSet rs = stmt1.executeQuery("<Query>");
I've used the following jar files: jtds-1.3.0, sqljdbc-4.1.5605, sqljdbc4-4.0
when I ran the code, I got the following error:
Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: The connection to the host <host-name>, named instance <instance-name> failed. Error: "java.net.SocketTimeoutException: Receive timed out". Verify the server and instance names and check that no firewall is blocking UDP traffic to port 1434. For SQL Server 2005 or later, verify that the SQL Server Browser Service is running on the host.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.getInstancePort(SQLServerConnection.java:3589)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.primaryPermissionCheck(SQLServerConnection.java:1225)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:972)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at first_doc.main(first_doc.java:28)
as far as I know, there is no firewall that's blocking traffic.
Also, do I need to add Port number as part of the Connection URL?
Edit: I use SQL server version 2008
I cannot find Protocols for SQLEXPRESS in the Configuration Manager
These are the steps that you need to do. If you already did this please check again.
Download latest MSSQL JDBC driver from here: http://msdn.microsoft.com/en-us/sqlserver/aa937724.aspx
Referenced the 2 JAR files in my project:
sqljdbc.jar and sqljdbc4.jar
(I'm not yet sure if both of the above are required or just one..)
Make sure the SQL Server Browser windows service is running
Open SQL Server Configuration Manager and go to Protocols for SQLEXPRESS under SQL Server Network Configuration. Right-click on TCP/IP and choose Properties.
Set Enabled = YES.
While you're there, click on IP Addresses tab and find the section IP All.
Set TCP Port to 1433.
Add sqljdbc_auth.dll to your PATH Environment Variable. In my case:
D:\Java\sqljdbc_4.0\enu\auth\x64
Copy the sqljdbc_auth.dll to your JDK directory. In my case:
C:\Program Files\Java\jdk1.7.0_04\bin

java and access error when connecting to the database

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

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:

Categories

Resources