Results 1 to 10 of 10
  1. #1
    sashaxiv is offline Member
    Join Date
    Feb 2011
    Location
    Spain
    Posts
    26
    Rep Power
    0

    Default JDBC sqlServer domain\user problem

    Hi all,
    I'm having problems trying to connect to a SQLServer instance.

    In the sqlServerManager i can only access the server running the SqlServerManager as another user (my user has no permission to connect the server). The user i am using to connect is in the form DOMAIN\otheruser

    This is my code:
    Java Code:
    public static String driverName  = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; // Start JDBC
    	public static String dbURL = "jdbc:sqlserver://myServer:2511;DatabaseName=myDB";   
    	
     
    	public static String userName="myuser";
    	public static String userPwd="mypass";
    
    	
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		
    		Connection dbConn;
    
    	       try 
    	       {
    	          Class.forName(driverName);
    	          dbConn = DriverManager.getConnection(dbURL,userName,userPwd);
    	          System.out.println("Connection Successful!");  
    	          // if successful print Connection Successful!
    	        } 
    	       catch (Exception e) 
    	       {
    	           e.printStackTrace();
    	        }
    		
    	}
    the error i got is:
    com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'myuser'.

    Any ideas? i also tried with "DOMAIN\myuser"
    Thanks in advance.
    Regards from Spain

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    "\\" not "\"

    "\" is an escape character in Java Strings, so, as with any Escape sequence, if you actually want to include the escape sequence, you need to escape the escape sequence, therefore "\\" instead of "\'".

  3. #3
    sashaxiv is offline Member
    Join Date
    Feb 2011
    Location
    Spain
    Posts
    26
    Rep Power
    0

    Default

    Yes, it was an error writing, in fact with one slash i would get a time-compiling error.

    I think the problem is related with windows autenticacion. I can only access SqlServerManager with windows autentication and running as other user (DOMAIN\user)

    How can I configure the JDBC connection properties to include the user DOMAIN?

    Is it only possible with the jdts driver?
    thanks in advance

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    No with "one-slash" you would not get a compile-time error. It's only a String.

    I say, try again.

  5. #5
    sashaxiv is offline Member
    Join Date
    Feb 2011
    Location
    Spain
    Posts
    26
    Rep Power
    0

    Default

    Yes, i have already tried :
    Java Code:
    public class Reporter {
    
    	/**
    	 * @param args
    	 */
    
    	public static String driverName_JDBC = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; // Start
    	public static String driverName_JDTS = "net.sourceforge.jtds.jdbc.Driver";
    
    	public static String dbURL_JDBC = "jdbc:sqlserver://myserver\\I2:2511;DatabaseName=myBd";
    	public static String dbURL_JDTS = "jdbc:jtds:sqlserver://myserver:2511/myBd";
    
    	public static String userName = "DOMAIN\\user";
    	public static String userPwd = "pass";
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    
    		Connection dbConn;
    		Properties pro = new Properties();
    		pro.put("username", userName);
    		pro.put("password", userPwd);
    
    
    		try {
    //			Class.forName(driverName);
    //			dbConn = DriverManager.getConnection(dbURL, pro);
    			Class.forName(driverName_JDBC);
    			dbConn = DriverManager.getConnection(dbURL_JDBC, pro);
    			System.out.println("Connection Successful!");
    			// if successful print Connection Successful!
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    
    	}
    
    }
    I'm now trying with jdts;

    Java Code:
    public static String driverName_JDBC = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; // Start
    	public static String driverName_JDTS = "net.sourceforge.jtds.jdbc.Driver";
    
    	public static String dbURL_JDBC = "jdbc:sqlserver://myserver\\I2:2511;DatabaseName=mybd";
    	public static String dbURL_JDTS = "jdbc:jtds:sqlserver://myserver:2511/mybd";
    
    	public static String userName = "domain\\user";
    	public static String userPwd = "pass";
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    
    		Connection dbConn;
    		Properties pro = new Properties();
    		pro.put("username", userName);
    		pro.put("password", userPwd);
    //		pro.put("domain", "CENTRAL");
    //		pro.put("instance", "I2");
    
    		try {
    			Class.forName(driverName_JDTS);
    			dbConn = DriverManager.getConnection(dbURL_JDTS, pro);
    //			Class.forName(driverName_JDBC);
    //			dbConn = DriverManager.getConnection(dbURL_JDBC, pro);
    			System.out.println("Connection Successful!");
    			// if successful print Connection Successful!
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    
    	}
    but i am also getting a similar error:
    java.sql.SQLException: Cannot open database "myBD" requested by the login. The login failed.
    Last edited by sashaxiv; 02-16-2011 at 12:49 PM.

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    That, if you will notice, is a different error.

  7. #7
    sashaxiv is offline Member
    Join Date
    Feb 2011
    Location
    Spain
    Posts
    26
    Rep Power
    0

    Default

    No, i don't agree with you, i think the error is the same, but with different drivers (jdbc - code1, jtds - code2).

    The only difference is that with jtds, i have used the domain prop trying to solve the error i'm getting with jdbc.

    Both of then are related with the login. I'm trying to connect SQLserver with a windows user, not a SQLServer user, and it is not my personal windows user.

    Any ideas?
    Thanks in advance

  8. #8
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    And what is the exact exception you get when not using jtds but with a double-slashed Domain username, and the exact error when not using the domain?

    Sorry, but I am having a hard time believing that you've tried it and gotten the same error after this "compile-time" complaint you made.

    Edit: P.S. You have checked the server configuration to make sure it takes general network connections, right?
    Last edited by masijade; 02-16-2011 at 02:19 PM.

  9. #9
    sashaxiv is offline Member
    Join Date
    Feb 2011
    Location
    Spain
    Posts
    26
    Rep Power
    0

    Default

    Ok, sorry about that.

    i'm getting tha same error using "myuser" or "DOMAIN\\myuser":

    com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user...
    com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user DOMAIN\user

    As i told you before i am trying to establish the connection witn a windows authentication user (the only one i have), not a SQL authentication user.

    If i try integratedSecurity=true my windows user has no rights, I have to use another one.

    I can run sql querys in SQLServerManager running the program as the user they gave me. I'm logging SQLServerManager in the form DOMAIN\user

  10. #10
    sashaxiv is offline Member
    Join Date
    Feb 2011
    Location
    Spain
    Posts
    26
    Rep Power
    0

    Default

    I have some news.

    I asked my partner to start a new Windows session with his user.
    Then i started eclipse and it works with jdts driver and the url connection in this way:

    dbURL_JDTS2= "jdbc:jtds:sqlserver://myServer:2511/myBD;instance=I2;useNTLMv2=true;domain=myDOMAIN"

    i don't know how to solve my problem using my windows account.
    Thank you everyone

    Edit: it also worked with the windows account of my partner and JDBC (i've downloaded the last version of the driver to support integratedSecurity=true) trying this url:
    dbURL_JDBC = "jdbc:sqlserver://myServer\\I2:2511;DatabaseName=myDomain;integrated Security=true";
    Last edited by sashaxiv; 02-16-2011 at 03:03 PM.

Similar Threads

  1. Cannot connect to sqlserver 2008 with JDBC
    By alexander.s in forum JDBC
    Replies: 4
    Last Post: 03-13-2011, 12:02 AM
  2. How to accept operator from user in jdbc ?
    By senidaljeet in forum JDBC
    Replies: 5
    Last Post: 05-13-2010, 08:59 AM
  3. JDBC commands for connecting to sqlserver
    By sudukrish in forum Advanced Java
    Replies: 7
    Last Post: 04-22-2009, 09:48 AM
  4. Replies: 1
    Last Post: 10-16-2008, 02:09 PM
  5. Would you like to become Domain reseller for Domain Auction?
    By Bettypeng in forum Reviews / Advertising
    Replies: 2
    Last Post: 05-12-2008, 08:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •