猿问

java连接sqlserver2008发生错误 Login failed for user 'sa'.

登陆时sqlserver服务器名是PC-201208120941\SQLEXPRESS(本机名称)

不能用.登陆,安装时的一点问题

myeclipse里的代码

Connection conn=null;
        
    try {
          Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");    
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    }
    try {
        String sql="select Id,BloodType from BloodType";
         conn=DriverManager.getConnection("jdbc:sqlserver://PC-201208120941\\SQLEXPRESS:1433;databaseName=myqq","sa","sa");//异常代码
        System.out.println("连接成功");

 


异常

com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'sa'.
    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(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
    at Ch10.text1.main(text1.java:22)
繁星coding
浏览 956回答 3
3回答

PIPIONE

用.NET的开发的时候有碰到过类似的问题,试下去把数据库连接改成远程连接试试。

茅侃侃

用户名和密码不一至

慕后森

一致着类。都是sa,在数据库都能登进去
随时随地看视频慕课网APP

相关分类

Java
我要回答