Pentaho Kettle: cannot connect to MS SQL Server Express - sql-server

I have Microsoft SQL Server 2014 Express running on my local machine, a Windows 7 PC.
I use Python and can connect to the server (from the very same PC) without any problems, using SQL alchemy. I can also connect using Excel and the PowerPivot add-in.
However, I cannot connect with Pentaho - Kettle.
I have downloaded the JDBC driver from Microsoft:
https://www.microsoft.com/en-gb/download/details.aspx?id=11774
I took the file jre8\sqljdbc42.jar and moved it to the lib subfolder of
the Pentaho Data Integration installation. I took the file in jre8, not jre7, because my Java is JRE1.8.0_144
I then took the file in auth\x86\sqljdbc_auth.dll and copied it to the same lib folder. I took the x86 file, not the x64, because Java is in c:\Program Files (x86)\Java\jre1.8.0_144\
I add 'table input' and set connection type= MS SQL Server (native) and Access = Native (JDBC)
The error message I get is:
Error connecting to database [mydatabase] :org.pentaho.di.core.exception.KettleDatabaseException: Error occurred while trying to connect to the database
Error connecting to database: (using class com.microsoft.sqlserver.jdbc.SQLServerDriver) 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.".
org.pentaho.di.core.exception.KettleDatabaseException: Error occurred while trying to connect to the database
Error connecting to database: (using class com.microsoft.sqlserver.jdbc.SQLServerDriver) 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 various combinations of specifying port number 1433 and of leaving it blank, of using integrated security and of entering my password manually, of setting host name to localhost and to DESKTOP-MYNAME\SQLEXPRESS, but to no avail.
I have read lots of discussions about it but none seems relevant; the SQL Server does accept incoming connections, e.g. from Python and SQL Alchemy.

I ran the SQL Server 2014 configuration manager, and checked:
SQL Server network configuration --> Protocols for SQLEXPRESS --> TCP/IP
In the protocol tab, I had: enabled: yes and Listen All: Yes
In the "IP Addresses" tab, under IPAll at the bottom, "TCP Dynamic ports" was set to 49178. (No idea why).
So I set the port in the 'table input' setup of Pentaho to 49178. It managed to find the server, but there was an error about integrated security. So I copied sqljdbc_auth.dll to both the bin and the lib subfolders of C:\Program Files (x86)\Java\jre1.8.0_144 .... and now it works!
If I don't specify the port, Pentaho tries port 1433, and it doesn't work.
For reference, the connection string I use with Python and SQL Alchemy does not specify the port explicitly.
params = '?driver=SQL+Server+Native+Client+11.0'
engine = create_engine('mssql+pyodbc://' + ServerName + '/'+ Database + params, encoding ='latin1' )
conn=engine.connect()

SQL Server network configuration --> Protocols for SQLEXPRESS --> TCP/IP
In the protocol tab, I had: enabled: yes and Listen All: Yes
In the "IP Addresses" tab, under IPAll at the bottom, "TCP Dynamic ports" was set to 49178.
So I set the port in the 'table input' setup of Pentaho to 49717.
this worked for me also..

Related

Connecting to SQLServer with GORM

I am using the statement below to try and open a connection to the latest download of SQLServer Express.
import (
"fmt"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mssql"
"log"
)
db, err := gorm.Open("mssql", "sqlserver://tony:Password6!#localhost:1433?database=go_user")
The statement results in an error:
2019/09/30 10:29:16 Unable to open tcp connection with host
'localhost:1433': dial tcp [::1]:1433: connectex: No connection could
be made because the target machine actively refused it. panic: Unable
to open tcp connection with host 'localhost:1433': dial tcp
[::1]:1433: connectex: No connection could be made because the target
machine actively refused it.
Is anyone successfully connecting to SQLServer Express with GORM on Golang?
TCP port 1433 is the default port for SQL Server. This port is also the official Internet Assigned Number Authority (IANA) socket number for SQL Server. Client systems use TCP 1433 to connect to the database engine; SQL Server Management Studio (SSMS) uses the port to manage SQL Server instances across the network. You can reconfigure SQL Server to listen on a different port, but 1433 is by far the most common implementation.
However, if you still want to open it, follow the below steps:
Step 1
Probably TCP/IP channel is disabled under SQL Server Configuration Manager. SO go there and enable all TCP/IP options.
Step 2
Just in case at the same place SQL Server Configuration Manager make sure you have 1433 port.
Step 3
Make sure that SQL server is configured to allow remote connections. Use MS SQL Management Studio and right click on the top node which server itself.
Credit from the solution found here.

SQL network-instance related issue (with error 258)

I get the following message when trying to connect to SQL database from a remote machine using MS Management Studio with Server Name [ XX.XXX.XXX.XXX,1433\MyServerName ] and SQL authentication:
Cannot connect to XX.XXX.XXX.XXX,1433\MyServerName.
ADDITIONAL INFORMATION:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - The wait operation timed out.) (Microsoft SQL Server, Error: 258)
The wait operation timed out
I have done the following:
Allowed remote connection in Server Properties window in SQL Management Studio
Configured server machine to have static IPv4/DNS addresses.
Enabled TCP/IP in SQL Configuration Manager (in SQL Server Network Configuration)
In TCP/IP properties, adjusted [ Protocol -> Listen All -> No ] & set IP[1-8] to TCP port 1433 and IPAll port to 1433 (TCP dynamic ports left blank)
Set Inbound/Outbound enable connection (Domain, public, private) rules in Windows Firewall for ports TCP 1433, UDP 1434 (should make no difference, since port is specified), service executables: sqlbrowser.exe in C:\Program Files (x86)\Microsoft SQL Server\90\Shared (not used I think because port is specified) and sqlservr.exe in C:\Program Files\Microsoft SQL Server\MSSQL13.MyServerName \MSSQL\Binn
Set NAT actions in server-side router for ports 1433 (TCP), 1434 (UDP) (again, should not matter) to server's local IPv4 address and ports 1433, 1434 accordingly.
Made sure SQL service is running, ports are open and listening on server machine.
I can connect to the database on server machine using Windows or Sql credentials with either PC name, or machine's local IPv4.
Interesting thing is, when >telnet XX.XXX.XXX.XXX 1433 is run, it takes about 10-12 seconds to fail (Could not open connection to the host, on port 1433: Connect failed), but I can see the 2 packets coming to the router itself. Same with the login using SQL Manager - packets come to the router, but either server machine refuses (doesn't resolve?) the connection, or it doesn't even get to the machine.
Appreciate your suggestions.
Versions used:
MS SQL Server 2016 Express, MS SQL Management Studio 17, SQL Server 2016 Configuration Manager, Windows 10 Pro.
Have you tried telnet on 1433 locally?
Are you sure your local connection is using TCP/IP? By default, local connections use DBNMPNTW (named pipes) which uses shared memory on the back end for local connections and is faster than TCP/IP.
When SQL Server is working correctly on TCP/IP telnet will connect and leave you blinking waiting for protocol-- it doesn't hang for 10-12 seconds and fail.
If telnet works locally but not remotely, then you know the problem is in the networking layer (firewall, NAT, routing, etc.). If it does not, then the problem is in the SQL configuration setup. Did you restart the service after changing the connection settings?

SQL server connection failed from application

While I run my spring boot application, which is trying to store data into MS SQL server database, it is unable to connect to Microsoft SQL database.
I am getting the following exception while running:
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host /sqlexpress, 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.".
In the code, in java class having main method, the bean method "dataSource()" is implemented as shown below:
#Bean
public DataSource dataSource(){
final DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
dataSource.setUrl("jdbc:sqlserver://<system_name>/sqlexpress:1433;databaseName=databasename");
dataSource.setUsername("username");
dataSource.setPassword("password");
return dataSource;
}
I am trying to connect using JdbcTemplate.
In gradle dependency, the following dependencies are added:
compile("org.springframework:spring-jdbc")
compile("com.microsoft.sqlserver:sqljdbc4:4.0")
From Microsoft SQL Server 2014 Management Studio, I could connect to the host system_name/sqlexpress, having port 1433.
I have checked the SQL server configuration manager -->
SQL Server Network Configuration --> Protocols for SQLEXPRESS --> TCP/IP .
It is enabled and in TCP/IP properties, TCP port of IPAll is set to 1433 only.
I couldn't identify why it is not getting connected when connection is trying from springboot application.
It is highly appreciable if you have any possible solution for this MSSQL connection issue.
Thanks
Basically you need to configure the TCP/IP in a hard coded way.
How to do that is very well explaned here configuring SpringBoot for MSSQL :
From the Start menu, open SQL Server 2014 Configuration Manager.
Click Protocol for SQLEXPRESS under SQL Server Network Configuration on the left pane.
On the right pane, right- click TCP/IP, and select Properties.
On the TCP/IP Properties dialog box that appears, click the IP Addresses tab. Scroll down to locate the IPALL node.
Remove any value, if present for TCP Dynamic Ports and specify 1433 for TCP
Port.
Now click OK and restart your SQL Server.

Use SQL Server Management Studio to connect remotely to an SQL Server Express instance hosted on an Azure Virtual Machine

Initial Attempt
I have an Azure VM with Windows Server 2012, on which I just installed SQL Server 2012 Express Database Engine component. Then, I followed the instructions here to connect remotely with SQL Server Management Studio.
Create a TCP endpoint for the virtual machine
Open TCP ports in the Windows firewall
Configure SQL Server to listen on the TCP protocol
Configure SQL Server for mixed mode authentication
Create SQL Server authentication logins
Determine the DNS name of the virtual machine
Connect to the Database Engine from another computer
After step seven I received the following error:
A network related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that
SQL Server is configured to allow remote connections. (provider: Named
Pipes Provider, error: 40 - Could not open a connection to SQL Server)
(Microsoft SQL Server, Error: 53)
What else do I need to configure before connecting remotely?
Troubleshooting
I have been following the troubleshooting instructions here. Each blockquote below is a step described that that link.
Confirm the instance of the SQL Server Database Engine is installed
and running.
Done. We installed SQL Server Express, and it is running as a named instance called SQLEXPRESS.
If you are attempting to connect to a named instance, make sure the
SQL Server Browser service is running.
Done. We followed the steps here to turn on the SQL Server Browser service.
Get the IP Address of the computer.
Done. We will use these later for testing connectivity and maybe for setting up a static port for SQLEXPRESS.
10.241.62.155
fe80::45c:8c29:e19f:f78b%15
Get the TCP port number used by SQL Server.
Done. The SQL Server Management Studio server logs showed that the server was listening on port 49169.
Enable Protocols
Done. We had already enabled TCP/IP in the configuration manager, but we restarted the SQL Server Service just in case.
Testing TCP/IP Connectivity
Done. We used tcping.exe to test connectivity (cmd ping doesn't work quickly with Azure.) We were able to connect to port 80.
tcping.exe buddha.cloudapp.net > successful
tcping.exe buddha.cloudapp.net 80 > successful
Testing a Local Connection
Done. We used sqlcmd.exe from the command prompt and were able to connect locally via TCP with a username and password.
sqlcmd -S Buddha\SQLEXPRESS (success via shared memory protocol)
sqlcmd -S tcp:Buddha\SQLEXPRESS (success via TCP)
sqlcmd -S tcp:Buddha\SQLEXPRESS -U sa -P (success via TCP with username)
sqlcmd -S tcp:10.241.62.155\SQLEXPRESS -U sa -P (success with internal IP)
Opening a Port in the Firewall
We opened the port on which we SQLEXPRESS listens. The server logs (above) showed that SQLEXPRESS was listening on port 49169, but this is just one of many dynamic ports, and we wanted to set up the static port 1435.
Use WF.msc to create an inbound TCP rule for port 1435.
Use Azure Management Portal to create a TCP endpoint for port 1435.
The troubleshooting instructions also say:
If you are connecting to a named instance or a port other than TCP
port 1433, you must also open the UDP port 1434 for the SQL Server
Browser service.
Since we are connecting SQLEXPRESS (a named instance), we needed to open port 1434 for UDP.
Use WF.msc to create an inbound UCP rule for port 1434.
Use Azure Management Portal to create a UDP endpoint for port 1434
Further research about connecting to named instances revealed dynamic port issues. The reason why we are using port 1435 (static) instead of port 49169 (one of many effective options.)
Instances of SQL Server Express, SQL Server Compact, and named
instances of the Database Engine use dynamic ports. To configure these
instances to use a specific port, see Configure a Server to Listen on
a Specific TCP Port (SQL Server Configuration Manager). and
here.
Done. We went to SQL Configuration Manager > SQL Server Network Configuration > Protocols for SQLEXPRESS > TCP/IP, we did the following.
Protocol Tab > Listen All > NO.
IP Addresses Tab > for each listed address
Enabled > Yes
TCP Dynamic Ports > Blank (delete the zero)
TCP Port > 1435 (or your choice)
After restarting the SQLEXPRESS service, we again looked in the SQL Server Management Studio logs, and found that the Server is Listening on port 1435!!! Hooray!
Testing the Connection
Done. We opened SQL Server Management Studio on our local (non-Azure) computer and connected.
buddha.cloudapp.net,1435 OR buddha.cloudapp.net\SQLEXPRESS
sa
password
Success.
Here are the three web pages on which we found the answer. The most difficult part was setting up static ports for SQLEXPRESS.
Provisioning a SQL Server Virtual Machine on Windows Azure. These initial instructions provided 25% of the answer.
How to Troubleshoot Connecting to the SQL Server Database Engine. Reading this carefully provided another 50% of the answer.
How to configure SQL server to listen on different ports on different IP addresses?. This enabled setting up static ports for named instances (eg SQLEXPRESS.) It took us the final 25% of the way to the answer.
The fact that you're getting an error from the Names Pipes Provider tells us that you're not using the TCP/IP protocol when you're trying to establish the connection. Try adding the "tcp" prefix and specifying the port number:
tcp:name.cloudapp.net,1433
I too struggled with something similar. My guess is your actual problem is connecting to a SQL Express instance running on a different machine. The steps to do this can be summarized as follows:
Ensure SQL Express is configured for SQL Authentication as well as Windows Authentication (the default). You do this via SQL Server Management Studio (SSMS) Server Properties/Security
In SSMS create a new login called "sqlUser", say, with a suitable password, "sql", say. Ensure this new login is set for SQL Authentication, not Windows Authentication. SSMS Server Security/Logins/Properties/General. Also ensure "Enforce password policy" is unchecked
Under Properties/Server Roles ensure this new user has the "sysadmin" role
In SQL Server Configuration Manager SSCM (search for SQLServerManagerxx.msc file in Windows\SysWOW64 if you can't find SSCM) under SQL Server Network Configuration/Protocols for SQLExpress make sure TCP/IP is enabled. You can disable Named Pipes if you want
Right-click protocol TCP/IP and on the IPAddresses tab, ensure every one of the IP addresses is set to Enabled Yes, and TCP Port 1433 (this is the default port for SQL Server)
In Windows Firewall (WF.msc) create two new Inbound Rules - one for SQL Server and another for SQL Browser Service. For SQL Server you need to open TCP Port 1433 (if you are using the default port for SQL Server) and very importantly for the SQL Browser Service you need to open UDP Port 1434. Name these two rules suitably in your firewall
Stop and restart the SQL Server Service using either SSCM or the Services.msc snap-in
In the Services.msc snap-in make sure SQL Browser Service Startup Type is Automatic and then start this service
At this point you should be able to connect remotely, using SQL Authentication, user "sqlUser" password "sql" to the SQL Express instance configured as above. A final tip and easy way to check this out is to create an empty text file with the .UDL extension, say "Test.UDL" on your desktop. Double-clicking to edit this file invokes the Microsoft Data Link Properties dialog with which you can quickly test your remote SQL connection

Can't connect to SQL Server via Microsoft SQL Server 2012 JDBC Driver

This is weird. I'm on a Mac OS X 10.7.5 64-bit host running VirtualBox 4.2.6. I've got a Windows 7 SP1 guest (64-bit) with bridged networking running Microsoft SQL Server Express 2012. I configured SQL Server to use TCP/IP on port 1433, not dynamic ports (setting is blank, not 0). The Windows 7 guest has IPv4 address 192.168.99.132 and Windows Firewall is turned off.
I downloaded the Microsoft SQL Server 2012 JDBC driver along with Squirrel SQL client 3.4.0 for both Windows and Mac. When I run Squirrel on the Windows 7 guest OS itself, I can connect to SQL Server just fine via the Microsoft JDBC driver using the guest machine names of either "winny", "localhost", or "192.168.99.132" (JDBC URLs like jdbc:sqlserver://winny\SQLEXPRESS:1433;databaseName=vha). However, when I try to connect to SQL Server from Squirrel running on the Mac host, I get an exception (see stack trace below).
Here's the weird part. If, from the Mac host, I use the jTDS SQL Server driver (version 1.2.7 because I'm using JDK6, so can't use jTDS 1.3.0 -- that version is JDK7 only), I connect right away with the JDBC URL jdbc:jtds:sqlserver://192.168.99.132:1433/vha.
Any ideas why the Microsoft driver fails but jTDS succeeds from a remote host? The only piece of infomration missing from the jTDS URL that's in the Microsoft one is the instance name ("SQLEXPRESS"). And yes, I've tried the Microsoft URL with and without the instance name.
Java version on the Mac host is:
java version "1.6.0_37"
Java(TM) SE Runtime Environment (build 1.6.0_37-b06-434-11M3909)
Java HotSpot(TM) 64-Bit Server VM (build 20.12-b01-434, mixed mode)
Java version on the Windows 7 guest is:
java version "1.6.0_35"
Java(TM) SE Runtime Environment (build 1.6.0_35-b10)
Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01, mixed mode)
Stack trace when connecting from Mac host to Windows 7 guest:
java.util.concurrent.ExecutionException: java.lang.RuntimeException: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 192.168.99.132, 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.".
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:232)
at java.util.concurrent.FutureTask.get(FutureTask.java:91)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.awaitConnection(OpenConnectionCommand.java:132)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.access$100(OpenConnectionCommand.java:45)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand$2.run(OpenConnectionCommand.java:115)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.RuntimeException: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 192.168.99.132, 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.".
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.executeConnect(OpenConnectionCommand.java:171)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.access$000(OpenConnectionCommand.java:45)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand$1.run(OpenConnectionCommand.java:104)
... 6 more
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 192.168.99.132, 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.".
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:241)
at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2243)
at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:491)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1309)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
at net.sourceforge.squirrel_sql.fw.sql.SQLDriverManager.getConnection(SQLDriverManager.java:133)
at net.sourceforge.squirrel_sql.client.mainframe.action.OpenConnectionCommand.executeConnect(OpenConnectionCommand.java:167)
... 8 more
In theory you also need the instance name in the jTDS connection string (e.g. appending ";instance=SQLEXPRESS") -- but I am not familair with jTDS and I might be wrong, but if you are not setting that and you are connecting then perhaps you are connecting to something else?
You showed your jTDS connection string above with the IP address and the Microsoft one with the server name "winny" (jdbc:sqlserver://winny\SQLEXPRESS:1433;databaseName=vha) -- have you tried the IP address? (jdbc:sqlserver://192.168.99.132\SQLEXPRESS:1433;databaseName=vha)
Things I usually try:
Verify the port -- can you telnet to localhost port 1433 on the host machine
Verify the network -- make sure the host responds to ping -- can you ping it by name from the client? By IP Address?
Verify port 1433 is open -- can you telnet from the client to the host on port 1433?
Because you can connect from the Mac client with jTDS you should be able to do all three of these already but it would be worth double checking.
You could also try hardcoding the port 1433 (change it from blank) on the server -- maybe another instance of SQL exists? See also http://support.microsoft.com/kb/287932
Here are some steps I usually go through, maybe this will help:
(Server) Open SSMS, right-click the SQL Server, Properties; verify that Allow Remote Connections is checked. If not, check and restart SQL Server.
(Server) Open SQL Server Configuration Manager (Start -> SQL Server -> Configuration Tools)
Verify that TCP/IP is Enabled
For default instance verify that static port 1433 is set (Note: a named instance will have a backslash, e.g. something like MYSQLSERVER\MYINSTANCE, whereas a default instance is identified with just the server name.)
For named instance choose another static port, e.g. 1434+, and set it as the static port. Only one per instance – do not re-use them on the same machine.
Restart SQL Server service
(Server) Verify that what you did worked so far; on SQL Server machine:
Open CMD prompt, "telnet localhost 1433" (change 1433 to other port number as appropriate)
If you get a blank screen that is "hung", it worked!
If you get an error, it did not work. Go back to square 1.
Try the same thing but using the machine name instead of localhost
(Server) Configure Windows Firewall to add an exception to TCP port 1433 (or whichever port you chose in step 2)
(Server) If using named instances, add another exception to UDP port 1433 as well (for the SQL Browser service, which uses UDP not TCP – also note SQL Browser Service ALWAYS uses port 1433 even if you chose a different TCP port for your instance in step 2)
(Client) Verify from another machine on the same network
Open CMD prompt, "ping " – if you get responses, the machines can see each other. Even if you do not get a response, try the next step – Windows 7 for example may default to NOT reply to echo requests (ping)
Open CMD prompt, "telnet 1433" (change 1433 to other port number as appropriate)
If you get a blank screen that is "hung", it worked!
If you get an error, it did not work. Go back to square 1.
(Client) Now try and connect to the SQL Server from another application like Excel
(Client) See also http://blogs.msdn.com/b/dataaccesstechnologies/archive/2010/01/29/testing-connection-to-sql-server-from-a-service-running-under-local-system-account.aspx for other errors
Step 1: Download jtds.jar from http://sourceforge.net/projects/jtds/files/
Step 2: Add the jar into eclipse or any IDE.
Step 3:
String driver="net.sourceforge.jtds.jdbc.Driver";
Class.forName(driver).newInstance();
String connString="jdbc:jtds:sqlserver://127.0.0.1:1433/database_name;encrypt=false;user=sa;password=yourpassword;integratedSecurity=true;instance=SQLEXPRESS;";
String username="sa";
String password="yourpassword";
OR
String connString="jdbc:jtds:sqlserver://192.168.1.198:1433/database_name;encrypt=false;user=sa;password=yourpassword;";
String username="sa";
String password="yourpassword";

Resources