简体   繁体   English

远程桌面SQL Server 2008连接错误

[英]Remoter desktop SQL server 2008 connection error

I am trying to connect sql server 2008 on remote desktop. 我正在尝试在远程桌面上连接sql server 2008。 My remote desktop IP is 192.168.175.174 . 我的远程桌面IP是192.168.175.174 The user is User3 , the password is user3 , and the database is apache_camel . 用户为User3 ,密码为user3 ,数据库为apache_camel

it give an error like this any buddy can help me to connection 它给这样一个错误,任何哥们都可以帮助我建立联系

com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'User3'.
at     com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196    )
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:246)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:83)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2532)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:1929)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:1917)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1416)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1061)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:833)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at database.Sqlserver_connection.main(Sqlserver_connection.java:22)

This is my class code: 这是我的课程代码:

package database;

import java.sql.*;

public class Sqlserver_connection {
    public static void main(String[] args) {

        // Create a variable for the connection string.
        String connectionUrl =        "jdbc:sqlserver://192.168.175.174:1433;DatabaseName=apache_camel;user=User3;password=user3";
        //String Connectionurl="jdbc:sqlserver://localhost:1433;DatabaseName=YourDBName;user=UserName;Password=YourPassword" 
        //"databaseName=HelloWorld;integratedSecurity=true;";

        // Declare the JDBC objects.
        Connection con = null;
        Statement stmt = null;
        ResultSet rs = null;

            try {
                // Establish the connection.
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                    con = DriverManager.getConnection(connectionUrl);
                    System.out.println(con);
                    // Create and execute an SQL statement that returns some data.
                    String SQL = "SELECT TOP 1000 [username],[password] FROM [apache_camel].[dbo].[login]";
                    stmt = con.createStatement();
                    rs = stmt.executeQuery(SQL);

                    // Iterate through the data in the result set and display it.
                    while (rs.next()) {
                        System.out.println(rs.getString(1) + " " + rs.getString(1));
                    }
            }

        // Handle any errors that may have occurred.
        catch (Exception e) {
            e.printStackTrace();
        }

        finally {
            if (rs != null) try { rs.close(); } catch(Exception e) {}
                if (stmt != null) try { stmt.close(); } catch(Exception e) {}
                if (con != null) try { con.close(); } catch(Exception e) {}
        }
    }
}

well, not sure if you "MUST" use SQLServer Driver, here is another driver you could use for the connection (it worked for me on pure java application and on android app), http://jtds.sourceforge.net/ is really easy to use and you could provide the users credentials throught class DriverManager the static method getConnection(String url, String username, String password), for instance: 好吧,不确定是否您“必须”使用SQLServer驱动程序,这是您可以用于连接的另一个驱动程序(它在纯Java应用程序和android应用程序上都对我有用), http://jtds.sourceforge.net/确实是易于使用,您可以通过类DriverManager的静态方法getConnection(String url,String username,String password)为用户提供凭据,例如:

Connection conn = DriverManager.getConnection("jdbc:jtds:sqlserver://192.168.3.67:1433/androiddb", "sa", "1234"); 连接conn = DriverManager.getConnection(“ jdbc:jtds:sqlserver://192.168.3.67:1433 / androiddb”,“ sa”,“ 1234”);

here is a post i made a few weeks ago and i answered myself, it shows specifically how to set the connection with jtds, yes it is for android, but you can skip the specific android steps (it works for MS SQL 2008, i test it on pure java program). 这是我几周前发表的帖子,我回答了自己,它专门显示了如何设置与jtds的连接,是的,它适用于android,但是您可以跳过特定的android步骤(它适用于MS SQL 2008,我测试了它在纯Java程序上)。

JTDS for MS SQL in android with ADT 具有ADT的android中的MS SQL的JTDS

hope to be helpful, regards. 希望能有所帮助,问候。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM