用户登录失败的C# [英] Login failed for user C#

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

问题描述

protected DataTable GetData(string Query)
{
          DataTable data = new DataTable();
          try
          {
                strConnectionString = "data source=(local);Integrated Security=True;initial catalog=ps_erdb;";
                string Query = "Select ErdbBuildNumbereMinor from DBVersion";
                using (sqlConnection = new SqlConnection(strConnectionString))
                {
                    sqlConnection.Open();
                    SqlCommand cmd = sqlConnection.CreateCommand();
                    cmd.CommandTimeout = intConnectionTimeout;
                    cmd.CommandText = Query;
                    data.Load(cmd.ExecuteReader());
                    sqlConnection.Close();
                }
                return data;
            }
            catch (Exception ex)
            {
        }
        return data;
}

以上code返回一个错误

the above code returns a error

不能登录请求打开数据库ps_erdb。登录   失败。用户登录失败MIG3-ESVTB \ HPSInstall。

Cannot open database "ps_erdb" requested by the login. The login failed. Login failed for user 'MIG3-ESVTB\HPSInstall'.

但是,当我手动打开SQL Server Management Studio中上面登录,我是能够连接到数据库并执行查询。

But when i manually open SQL Server Management Studio with above login ,i was able to connect to database and execute the query.

推荐答案

有几个可能性考虑:

  1. 您登录时使用本地客户机上有什么用户进行?您的连接 字符串表示您使用的是集成安全性,以便应用程序将 present您当前登录的凭据到SQL Server。为了帮助诊断, 请确保您启用登录审核为不合格和放大器;成功 登录。当你从SSMS的连接和运行SELECT SUSER_NAME(),这是什么回报?

  1. What user were you logged in with on your local client? Your connection string indicates you're using integrated security so the application will present your current logged in credentials to SQL Server. To help diagnose, make sure you enable login auditing for both failed & successful logins. When you connect from SSMS and run SELECT suser_name(), what does it return?

是数据库的MULTI_USER模式(默认)或SINGLE_USER设置 模式?有人可能将其改为SINGLE_USER。这允许 第一个也是唯一一个连接。所有后续尝试将失败。如果是在单用户模式下,只需运行SSMS ALTER DATABASE ps_erdb SET MULTI_USER

Is the database set for multi_user mode (default) or single_user mode? Someone may have changed it to single_user. This allows the first and only one connection. All subsequent attempts will fail. If it's in single user mode, just run ALTER DATABASE ps_erdb SET MULTI_USER from SSMS

当你通过SSMS登录,是你能够查询的数据 ps_erdb数据库?如果没有,请确保你有一个数据库用户映射 到MIG3-ESVTB \ HPSInstall的登录和用户(不登录),授予相应的权限。

When you login via SSMS, were you able to query data from the ps_erdb database? If not, make sure you have a database user mapped to the 'MIG3-ESVTB\HPSInstall' login and the appropriate permissions granted to the user (not the login).

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

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