I am learning SQL/SQL Server 2012. I am also learning how to make forms with java using NetBeans. I am trying to link java to my SQL Server 2012 Express so I can make a form that uses/updates data in a SQL database but have not been successful.
I have done lots of research trying to find a solution and made changes that I found I needed to make. I have set up SQL Server to use TCP port 1433 on my computer. I have also made an exception in my firewall to allow that incoming connection. I have created a user "admin" and given that user sysadmin role. I have also set up SQL Server to allow remote connections with a time out of 60 seconds.
When I try to connect to the SQL Server from MS SQL Server Management Studio and put my computers static IP and port 1433, I get the attached error:
When I try to connect to the SQL Server database from NetBeans I get this:
Cannot establish a connection to
jdbc:sqlserver://DEVINSPC\SQLEXPRESS;databaseName=Test using
com.microsoft.sqlserver.jdbc.SQLServerDriver (The TCP/IP connection to
the host DEVINSPC, 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.".)
I am using jdbc4.2.jar file. I have set SQL Server to use both SQL Server and Windows Authentication. Hopefully this all makes sense.
If you need anymore info let me know. Any help is appreciated!
Related
I'm learning Java EE, and I'm trying to open a connection to my SQL Server database running on a Docker image. I obviously get the
Cannot create PoolableConnectionFactory (The TCP/IP connection to
the host localhost/DB_DEMO, port 1433 has failed.
With
docker ps -a
I get 0.0.0.0:1433->1433/tcp under "Ports" for my SQL Server image.
I know that we can use SQL Server Configuration Manager to allow TCP/IP connections, but I can't seem to find how to install it without installing the full SQL Server suite.
So, is there a way to enable TCP/IP on my SQL Server running in a Docker container? Or something I don't get in the whole "TCP/IP" thing?
EDIT [SOLVED]:
I get this error with this url (Microsoft docs said 1433 is used by default if port isn't specified):
url="jdbc:sqlserver://localhost/DB_DEMO"
It worked using the {property=key} format:
url="jdbc:sqlserver://localhost;databaseName=DB_DEMO"
I've been doing too much tweeking at once while going back and forth these two formats, and my bad, I thought the problem wasn't there (I took the server/DBName format from a a documentation though). Lesson learned!
Like Mark Rotteveel replied, the TCP/IP is certainly enabled by default on the Docker image anyway.
I have a machine(A) that has access to the host running the Oracle listener. I can connect to it fine using SQL Developer.
I have another machine(B) that I would also like to make a connection to the same database but its doesn't have direct access to the host running the listener. However, it does have access to machine (A).
I would like to forward a port on machine A to the Oracle listener host which is listening on port 1521.
Then I should be able to make a database connection from machine B to machine A and then forward a port to the host that has the Oracle listener. Sort of a man in the middle.
However, I'm running into issues. I can't even connect to the Oracle database from machine B using the forwarded port. I have experience using ssh tunnels to do the same thing. In this case, I'm not using ssh and I don't understand why this will not work.
Below is the procedure I'm going through:
Log into machine B - Oracle client is installed. SQL Developer is installed.
Open SQL Developer - Select TNS connection. Enter in credentials. Connection Successful
TNS Names entry:
CRYSTAL=(DESCRIPTION=(ADDRESS_LIST=(LOAD_BALANCE=yes)(FAILOVER=ON)(ADDRESS=(PROTOCOL=TCP)(HOST=testhost.com)(PORT=1521)))(CONNECT_DATA=(service_name=svc1)))
Now setup forwarding:
C:\Windows\system32>netsh interface portproxy add v4tov4 listenaddress=127.0.0.1
listenport=1521 connectaddress=testhost.com connectport=1521
protocol=tcp
If I telnet localhost 1521 , it is able to make a connection.
As a simple test, I make sure I can connect on Machine B using SQL Developer. But this time, I set the connection type to advanced so I can enter the jdbc url.Note, I use 127.0.01 instead of testhost.com because it will be forwarded to testhost.com
jdbc:oracle:thin:#(DESCRIPTION=(ADDRESS_LIST=(LOAD_BALANCE=yes)(FAILOVER=ON)(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))(CONNECT_DATA=(service_name=svc1)))
This connection fails with "ORA-12516, TNS: listener could not find available handler with matching protocol stack"
I've checked for firewall issues and made sure port 1521 is open.
Any ideas what I might be missing or has anyone else had success forwarding a port to an Oracle listener?
Thanks to the comment from psaraj12, I knew my approach should work. The problem I was having was due to the host name I was given to connect to the database. It works fine if you enter it into SQL Developer as is. However, when I used it in the port forwarding, I could not connect to the database using SQL Developer using the host name localhost. The host name I was given had "scan" in the name. I think this is a Virtual IP. We use Oracle RAC which is a clustering technology. So I suspected to that the VIP selected a node on the cluster and the forwarder could not handle it. So this is how I solved the problem:
Installed Wireshark.
Start recording packets.
Used SQL Developer To Connect with the VIP - Success
In Wireshark, find the TCP Stream that contains something unique about the connection. In this case, the Oracle service name. You should see the IP of the VIP. Something like:
.........6.,.A ...O........:..............................(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=11.3.68.171)(PORT=1521))(CONNECT_DATA=(CID=(PROGRAM=SQL Developer)(HOST=jdbc)(USER=adpc))(SERVICE_NAME=svc1)(CID=(PROGRAM=SQL Developer)(HOST=jdbc)(USER=adpc)))).................6.,.A ...O........:..............................(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=11.3.68.171)(PORT=1521))(CONNECT_DATA=(CID=(PROGRAM=SQL Developer)(HOST=jdbc)(USER=adpc))(SERVICE_NAME=svc1)(CID=(PROGRAM=SQL Developer)(HOST=jdbc)(USER=adpc)))). .......6.A ........ ..........................
Now, go back to the packet and find out what the "real" address is. Here is an example:
Wire shark packet information. This is the destination IP where Oracle listener is.
Now use this to forward the port.
netsh interface portproxy add v4tov4 listenport=1521 connect address=11.3.68.135 connectport=1521 protocol=tcp
Now, when you log in using SQL Developer Basic Connection Type, you can use localhost instead of the VIP and you should be able to connect.
Now, go to another machine that has access to the machine you just set up and you should be able to connect to the database from there as well using the IP of the machine where you have port forwarding setup.
The same forward connection is working fine in both basic and advanced connection in SQL developer in my machine.
The only difference is machine A,B and Database are in the same network in my case where B can directly connect to the database also
Steps
1)You have to set up forwarding in machine A with machine A ip address as the listen address
2) Use the machine A ipaddress in TNS to connect to Database in machine B
If still, you are facing problems then you can try enabling log and trace files to identify the issue as mentioned in these articles
Oracle Database 10g Debugging Connection problems 1
Oracle Database 10g Debugging Connection problems 2
My java web application connects to remote MSSQL server database by using JDBC. The address is a web URL: https://mssql2008.server.com. It works well on my PC. However, after I deployed it to Tomcat 9 on VPS CentOS 7. I got an error as follows:
com.company.app.utils.DBConnection. nullcom.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host mssql2008.server.com, port 1433 has failed. Error: "mssql2008.server.com. 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 have checked my MSSQL server and the port is opened and I can connect from my PC with only URL (without port). I also used PHP app on VPS for trying to connect but it also fails by login timeout ERROR
SQLSTATE[HYT00]: [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired
Is there anyone knows what happens? I think the problem is raised from my VSP CentOS. Do I need to install anything more on my VPS to let it can connect to MSSQL? or Is this a firewall problem?
Thank you in advance,
I am running a project in Eclipse that uses JDBC drivers. However, every time I run it I get the following error:
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.".
I am sure that the SQL Server Management Studio is using the 1433 port as well. But I want to verify it. Can someone tell me where do I go to check? I've been playing around with SQL Server for the past one hour and I can't find the slightest clue as to where it is.
Thanks in advanced.
Load up SQL Server configuration manager from start menu and check the network config. as per screenshot: http://tinypic.com/r/2hcgfgg/5
Go to start > Programs > Microsoft SQL Server > Configuration Tools > SQL Server Configuration Manager
Expand SQL Native Client 10.0 Configuration. Click Client Protocols. Make sure TCP/IP is enabled. Then double click TCP/IP. The port should be listed under Default Port.
I use the telnet trick to test if I can connect to a port and make sure it's not something else blocking my connection. Open a command prompt from the client and type: telnet hostname 1433
If you get a blank black screen you've connected successfully on port 1433. If you get a connection error then you know the port is blocked somewhere.
I am totally new to MySQL Server but good at Java! I know how to connect with the MySQL Server using Java. Recently, I have made a simple small MySQL Server (Test) app for me. Its just for my knowledge! I have successfully connected to the database and successful to use INSERT and SELECT Statements in my Java App.
The problem is that my app is only running on my that laptop on which the SQL Server 2008R2 is installed on! I just checked my app on my another Laptop and it says the following error:
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.
I have tried this link so far no Success an still I can't access my Data Base on my other machine!
msdn.microsoft.com/en-us/library/ms175043.aspx
From an answer i also tried my best!
stackoverflow.com/a/12430561/2496503
From this answer i have come to know that my SQL Server Network Configuration(32-bit) is not showing any details/options as mentioned in the above answer here is a snapshot attached herewith !
PLEASE TELL ME IF IT IS ORDINARY THING THAT IT IS NOT SHOWING ANY OPTIONS! ELSE MY SQL SERVER ISN'T INSTALLED CORRECTLY PLEASE HELP ME GIVE ME JUST HINTS I WILL BE THANKFUL TO YOU !
Perform these Steps for TCP/IP network Configuration upto step 6, ur problem will be solved.
[http://www.visual-paradigm.com/support/articles/solve-sql-server-connection-problem.jsp][1]