Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Programming / Connectivity / July 2008

Tip: Looking for answers? Try searching our database.

JTDS Driver Connect Problem - one works, one doesn't

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
WSalomon - 10 Jul 2008 18:01 GMT
I'm having a problem connecting to SQL-Server 2005 using the JTDS 1.22 JDBC
driver.

This occurs for only one of two SQL-Server 2005 instances I have.  The  
specifics are:

I have two machines, each loaded with SQL-Server 2005, one a 64-bit Server,
and one a 32-bit Laptop for development/demo purposes.  The setups are
similar, but obviously not identical.

Server -
WinXP 64-bit SP2
SQL-Server 2005 64-bit - Windows Authorization (WA) and sa/password logins
SouceForge JTBS 1.22 JDBC driver
Oracle SQL-Developer 1.54 (target app which needs JTBS driver - the MS JDBC
doesn't work)

Laptop -
WinXP 32-bit SP3
SQL-Server 2005 32-bit - Windows Authorization and sa/password logins
SouceForge JTBS 1.22 JDBC driver
Oracle SQL-Developer 1.54 (target app which needs JTBS driver - the MS JDBC
doesn't work)

In short - they are very similar and the PATH's and CLASSPATH's are
virtually identical (save for C:\Program Files and C:\Program Files (x68)
which are altered as needed.on the 64-bit machine).

What works: Both the Server and the Laptop can log into the SQL-Server
64-bit instance on the Server without difficulties using the JTBS driver.  
From the Server, I can use both WA and SA/password login, and can use a
machine name for either "localhost" or the server-name.  From the Laptop, I
can use SA/password login and server-name.  The JTBS driver is using port
1433 (default).  Also, I can hit the Server database with the SQL-Server
native ODBC driver without difficulty from both machines (as expected).

What doesn't work: Both the Server and the Laptop *cannot* log into the
SQL-Server 32-bit instance on the Laptop using the JTBS driver.  From the
Laptop, I've tried using both WA and SA/password login, and have tried using
both the "localhost" and the server-name, all without success.  From the
Server, I've tried SA/password login and server-name, again without success.  
The JTBS driver is using port 1433 (default).  Each time I end up with
"cannot connect to database" errors, presumably from  the JTBS driver.  
Paradoxically, I can hit the Laptop database with the SQL-Server native ODBC
driver without difficulty from both machines.

This makes no sense to me given that I thought I had set up the SQL-Servers
almost identically, and that I can hit both databases with ODBC, but not
JDBC.  One thought is there is some privileging problem, or maybe port 1433
is not the right one.

Any thoughts?

Thanks!
Evan T. Basalik (MSFT) - 15 Jul 2008 21:44 GMT
Do you have the same problem with the Microsoft JDBC driver (http://www.microsoft.com/downloads/details.aspx?FamilyId=C47053EB-3B64-4794-950D-
81E1EC91C1BA&displaylang=en) using the code below?

import java.*;

public class Connect{
    private java.sql.Connection  con = null;
    private final String url = "jdbc:sqlserver://";
    private final String serverName= "evanbagx620\\sql2007";
    private final String portNumber = "4141";
    private final String databaseName= "AdventureWorks";
    private final String userName = "username";
    private final String password = "password";
    // Informs the driver to use server a side-cursor,
    // which permits more than one active statement
    // on a connection.
    private final String selectMethod = "cursor";

    // Constructor
    public Connect(){}

    private String getConnectionUrl(){
         return url+serverName+":" + portNumber +";databaseName="+databaseName+";selectMethod="+selectMethod+";";
    }

    private java.sql.Connection getConnection(){
         try{
             Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
              con = java.sql.DriverManager.getConnection(getConnectionUrl(),userName,password);
              if(con!=null) System.out.println("Connection Successful!");
         }catch(Exception e){
              e.printStackTrace();
              System.out.println("Error Trace in getConnection() : " + e.getMessage());
        }
         return con;
     }

    /*
         Display the driver properties, database details
    */

    public void displayDbProperties(){
         java.sql.DatabaseMetaData dm = null;
         java.sql.ResultSet rs = null;
         try{
              con= this.getConnection();
              if(con!=null){
                   dm = con.getMetaData();
                   System.out.println("Driver Information");
                   System.out.println("\tDriver Name: "+ dm.getDriverName());
                   System.out.println("\tDriver Version: "+ dm.getDriverVersion ());
                   System.out.println("\nDatabase Information ");
                   System.out.println("\tDatabase Name: "+ dm.getDatabaseProductName());
                   System.out.println("\tDatabase Version: "+ dm.getDatabaseProductVersion());
                   System.out.println("Avalilable Catalogs ");
                   rs = dm.getCatalogs();
                   while(rs.next()){
                        System.out.println("\tcatalog: "+ rs.getString(1));
                   }
                   rs.close();
                   rs = null;
                   closeConnection();
              }else System.out.println("Error: No active Connection");
         }catch(Exception e){
              e.printStackTrace();
         }
         dm=null;
    }

    private void closeConnection(){
         try{
              if(con!=null)
                   con.close();
              con=null;
         }catch(Exception e){
              e.printStackTrace();
         }
    }

    public static void main(String[] args) throws Exception
      {
         Connect myDbTest = new Connect();
         myDbTest.displayDbProperties();
      }
}

--------------------
>Thread-Topic: JTDS Driver Connect Problem - one works, one doesn't
>thread-index: Acjiromu11DpsGVOR6ShIAjHkWf9YQ==
[quoted text clipped - 73 lines]
>
>Thanks!

Evan T. Basalik
This posting is provided “AS IS” with no warranties, and confers no rights.
WSalomon - 16 Jul 2008 06:32 GMT
Evan -

Thanks for you post.

Problem is solved - I delved in SQL-Server Configuration Manager, and
changed the settings to (which match those on the  working Server):

SQL-Server 2005 Network Configuration-- Protocols for SQL$SERVER instance
-- -- TCP/IP Properties
-- -- -- Addresses
-- -- -- -- IP1 - TCP Port 1433
-- -- -- -- IPAll - TCP Port 1433

I'll be keeping your code snippet for future reference.

Thanks!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.