Search code examples
javasql-serverjdbcfitnessedbfit

SQLServerException while trying to use Fitnesse and DbFit and SQL Server


I am new to both (Java) FitNesse and SQL Server, I want to have a basic SQL test working with DbFit,

I have the following in root:

!path c:\fitnesse\lib\dbfit.jar
!path c:\fitnesse\lib\fitlibrary.jar
!path c:\fitnesse\lib\sqljdbc4.jar
|Import|
|dbfit.SqlServerTest|

I have the following in my HelloWorldTest,

!contents -R2 -g -p -f -h

!|dbfit.SqlServerTest|

|Connect|LOCALSQLEXPRESS|sa|Password|somePassword:|

|eg.Division|
|numerator|denominator|quotient?|
|10       |2          |5        |
|12.6     |3          |4.2      |
|100      |4          |33       |  

What I have tried:

  • I have double checked my SQLExpress username and password and the SqlServer instance is at localhost.I doubt this is a firewall issue. (My understaning of firewall is quite weak admittedly.)
  • Looking at Sql Server Configuration Manager (SSCM),
    • I see that "SQL Server (SQLEXPRESS) is running as Process with ID 2316,
    • Using the PowerShell command "nestat -a -no | Select-String 2316", I see that the process on port 55618.
  • In SSCM, I then create alias called "LOCALSQLEXPRESS" in both "SQL Native Client 11.0 Configuration (32bit)" and "SQL Native Client 11.0 Configuration" as I have no idea what my JDBC is using. (Apparently, JDBC for SQL Server does not support named instance, I got an exception telling me so when I was trying to connect to \localhost\SQLEXPRESS directly) I have also enabled "TCP/IP" and "Shared Memory" in "Protocols for SQLEXPRESS".

I am getting the following error when I run the test:

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host LOCALSQLEXPRESS, 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.".

(Note the port number of 1433, despite my alias point to port 55618.)

This is my first post at StackOverflow, please excuse any silliness. Can anyone shed any light?


Solution

  • I'm hoping lingo_journey already had worked out the issue by now. For others who may have same problem, I initially also couldn't make the named instance work with the multi-parameter Connect.

    To solve the issue, I switched to connection string as parameter for Connect:

    1) ensured that the SQL Server Browser service is running (as mentioned in the comments above)

    2) changed the Connect parameter as below:

    !| Connect | jdbc:sqlserver://localhost\SQLEXPRESS;databaseName=DB_NAME;integratedSecurity=true |
    

    The following worked as well using the SQL Server authentication (which is probably more applicable to lingo_journey:

    !| Connect | jdbc:sqlserver://localhost\SQLEXPRESS;databaseName=DB_NAME;user=user1;password=Welcome!|
    

    Note than in some examples I saw on the web, the sqlserver: has been omitted from the connection string which did not work for me.