jdbc.SQLServerException:任何用户的登录失败

我试图测试与本地sql DB的连接。我有这个代码:

try{

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();

DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=SocialFamilyTree;user=SOSCOMP");

}catch(Exception e){

System.out.println("Couldn't get database connection.");

e.printStackTrace();

}

我尝试了很多用户。我的Windows用户是SOSCOMP,没有密码。我也知道SQL 2008将用户创建为“ sys”“

dbo”,我也尝试过这些。我总是得到:

Couldn't get database connection.

com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'SOSCOMP'.

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:579)

at java.sql.DriverManager.getConnection(DriverManager.java:243)

at FT_Receiver.FT_Receiver.main(FT_Receiver.java:12)

有任何想法吗?

谢谢

回答:

如果尝试连接使用Windows身份验证的数据库,则可以在连接字符串中使用“ integratedSecurity”选项。

DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=SocialFamilyTree;integratedSecurity=true;");

以上是 jdbc.SQLServerException:任何用户的登录失败 的全部内容, 来源链接: utcz.com/qa/416853.html

回到顶部