System.Data.SqlClient.SqlException:用户登录失败...在System.Data.SqlClient.SqlInternalConnectionTds

时间:2016-09-16 09:06:17

标签: c# sql asp.net azure

我知道这个问题之前已被问过几次,但所给出的解决方案根本没有帮助我。 我有一个Azure数据库,当我的屏幕加载时,我得到异常错误:

  

System.Data.SqlClient.SqlException(0x80131904):用户登录失败   '阮&#39 ;.在   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity   identity,SqlConnectionString connectionOptions,SqlCredential   凭证,Object providerInfo,String newPassword,SecureString   newSecurePassword,Boolean redirectedUserInstance,SqlConnectionString   userConnectionOptions,SessionData reconnectSessionData,   DbConnectionPool池,String accessToken,Boolean   applyTransientFaultHandling)at   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions   options,DbConnectionPoolKey poolKey,Object poolGroupProviderInfo,   DbConnectionPool池,DbConnection owningConnection,   DbConnectionOptions userOptions)at   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(类DBConnectionPool   pool,DbConnection owningObject,DbConnectionOptions选项,   DbConnectionPoolKey poolKey,DbConnectionOptions userOptions)at   System.Data.ProviderBase.DbConnectionPool.CreateObject(的DbConnection   owningObject,DbConnectionOptions userOptions,DbConnectionInternal   oldConnection)   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(的DbConnection   owningObject,DbConnectionOptions userOptions,DbConnectionInternal   oldConnection)   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(的DbConnection   owningObject,UInt32 waitForMultipleObjectsTimeout,Boolean   allowCreate,Boolean onlyOneCheckConnection,DbConnectionOptions   userOptions,DbConnectionInternal&连接)   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(的DbConnection   owningObject,TaskCompletionSource 1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource 1重试,DbConnectionOptions   userOptions,DbConnectionInternal oldConnection,   DbConnectionInternal&安培;连接)   System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(的DbConnection   outerConnection,DbConnectionFactory connectionFactory,   TaskCompletionSource 1 retry, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource 1重试,DbConnectionOptions userOptions)at   System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource 1 retry) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource 1   重试)在System.Data.SqlClient.SqlConnection.Open()处   Ticketing.LogNewTicket.Page_Load(Object sender,EventArgs e)in   C:\用户\管理员\桌面\项目\项目\票务\票务\ LogNewTicket.aspx.cs:行   62 ClientConnectionId:92cb895a-8433-45d3-9c8c-19120f9a5c19错误   号码:18456,状态:1,类别:14

我保证我的错误发生在这里,因为它没有填充下拉列表。

try
            {
                //con.Open();

                ListItem blank = new ListItem("<Priority>");
                blank.Value = "0";
                ddlPriority.Items.Add(blank);

                string cmdText = "SELECT * FROM Priority ";
                using (SqlConnection sqlConnection = new SqlConnection(con.ConnectionString))
                {
                    sqlConnection.Open();
                    using (SqlCommand sqlCommand = new SqlCommand(cmdText, sqlConnection))
                    {
                        using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
                        {
                            while (sqlDataReader.Read())
                            {
                                ListItem itemPriority = new ListItem(sqlDataReader.GetString(1).ToString());
                                itemPriority.Value = sqlDataReader.GetInt32(0).ToString();
                                ddlPriority.Items.Add(itemPriority);
                            }
                        }
                    }
                    sqlConnection.Close();
                }
            }

            catch (Exception ex)
            {
                lblSetPriority.Text = ex.ToString();
            }
        }

我的连接字符串如下所示:

我的连接字符串:

Data Source=xxx.database.windows.net;Initial Catalog=TicketsSupport;Integrated Security=False;User ID=ruan;Password=********;Connect Timeout=60;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False

连接到azure数据库后从属性中的visual studio复制的连接字符串。将****的密码更改为实际密码。

在web.config中:  

我尝试添加以下内容:

<machineKey validationKey="xxx" decryptionKey="xxx" validation="SHA1" decryption="AES"/>

<authentication mode="Windows"/>

我的主数据库有一个名为&#34; ruan&#34;

的用户

我在我的主人身上使用了以下内容:

SELECT * FROM sys.database_principals

当我添加我的用户时,我只执行以下操作:

CREATE LOGIN ruan WITH PASSWORD = 'abc123', 

我不知道还有什么可以尝试的。

0 个答案:

没有答案