SQL Server Azure “Login failed for User”

久未见 提交于 2019-12-11 03:47:08

问题


I am using the following code to perform SQL commands to my azure DB. The I do two calls inside my ASP.NET MVC action method. One to delete from Table A, and the second call to delete from Table B.

  using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(ConnectionString))
        {
            using (System.Data.SqlClient.SqlCommand command = conn.CreateCommand())
            {
                conn.Open();
                command.CommandText = statement;
                command.ExecuteNonQuery();
            }
        }

For whatever reason when I make the second call to this code (I have it in a Helper service class, it bombs with the following Azure error.

Additional information: Login failed for user 'MyUser'.

Is there something I'm not doing correctly but not perhaps closing a connection or something that Azure is having issues with this?


回答1:


You need allow your IP Address to access azure database. click in configure and add your IP.




回答2:


I just needed add to the connection string

Persist Security Info=False;



回答3:


when you publish your project into azure from visual studio, there is a 'settings' tab on the left.

go to the settings. it will show you the connection string that you're using in the web.config.

what worked for me is I unchecked the check box that says 'Use this connection string at runtime (update destination web.config)' and everything went well for me.



来源:https://stackoverflow.com/questions/24510804/sql-server-azure-login-failed-for-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!