SqlServer:用户登录失败 [英] SqlServer: Login failed for user

查看:628
本文介绍了SqlServer:用户登录失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个非常简单的jdbc登录测试程序.在遇到各种问题之后,我几乎都可以正常工作了.几乎,似乎似乎无法摆脱这个"SQLServerException:用户xxxxx登录失败"的问题.

I've written a very simple jdbc login test program. And after all kinds of problems I've almost got it working. Almost, just can't seem to get past this "SQLServerException: Login failed for user xxxxx" problem.

我创建了一个简单的数据库PersonInfo,然后创建了用户user1 password1(sql身份验证).尝试之后,所有内容都无法连接到数据库.

I created a simple database PersonInfo then I created user user1 password1 (sql authenication). And after trying everything was unable to connect to the database.

我在Win 7上使用SqlServer2008,我从Microsoft获得了最新的jdbc驱动程序.

I am using SqlServer2008 on Win 7, I'v got the latest jdbc driver from Microsoft.

我的代码是:

import java.sql.*;

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

    try {
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
Connection conn=  DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=PersonInfo;user=Sohaib;password=0000;");


System.out.println("connected");
       }

    } catch (Exception e) {
        e.printStackTrace();
    }
}
}

这是例外

Exception: Unable to get connect
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'Sohaib'.
and all other supporting errors..

不幸的是,在某种SqlServer Guru或Jdbc Guru怜悯我并帮助我之前,我现在已经死在水中了.

Unfortunately I am now dead in the water until some kind SqlServer Guru or Jdbc Guru take pity on me and helps me out.

提前谢谢.

推荐答案

您的SQL Server是否处于混合模式身份验证"状态?使用SQL服务器帐户而不是Windows登录名是必需的.

Is your SQL Server in 'mixed mode authentication' ? This is necessary to login with a SQL server account instead of a Windows login.

您可以先检查服务器的属性,然后再检查安全性,以确保此状态,该服务器应处于"SQL Server和Windows身份验证模式".

You can verify this by checking the properties of the server and then SECURITY, it should be in 'SQL Server and Windows Authentication Mode'

如果用户尝试使用无法验证的凭据登录,则会出现此问题.在以下情况下可能会发生此问题:

This problem occurs if the user tries to log in with credentials that cannot be validated. This problem can occur in the following scenarios:

方案1:该登录名可能是SQL Server登录名,但服务器仅接受Windows身份验证.

Scenario 1: The login may be a SQL Server login but the server only accepts Windows Authentication.

方案2:您正在尝试使用SQL Server身份验证进行连接,但是SQL Server上不存在使用的登录名.

Scenario 2: You are trying to connect by using SQL Server Authentication but the login used does not exist on SQL Server.

方案3:该登录名可能使用Windows身份验证,但该登录名是无法识别的Windows主体.无法识别的Windows主体意味着Windows无法验证登录名.这可能是因为Windows登录名来自不受信任的域.

Scenario 3: The login may use Windows Authentication but the login is an unrecognized Windows principal. An unrecognized Windows principal means that Windows can't verify the login. This might be because the Windows login is from an untrusted domain.

用户输入的信息也不正确.

It's also possible the user put in incorrect information.

http://support.microsoft.com/kb/555332

http://support.microsoft.com/kb/555332

这篇关于SqlServer:用户登录失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆