locked
SQL Azure Server Login Failed RRS feed

  • Question

  • User-1286266314 posted

    Hi,

    I am trying to create a connection string in Web.config of my website.

    My SQL Server database is hosted with Azure.

    I have this database displayed in 'Server Explorer' in Visual Studio. I opened the database properties, and copied the connection string.

    However, when I try to access the database, I still get this error: 

    Login failed for user '{username}'.

    I know the username and password are correct, because I have used them to access the database previously in Microsoft SQL Server Management Studio.

    I have read online about allowing different forms of authentication.

    One link said to go to the database's properties and change the security, but I was unable to find the properties tab for the actual database.

    Can any of you guys help fix this problem?

    Here is the connection string in my Web.config:

     <connectionStrings>
        <add name="FYPConnectionString1" 
             connectionString="Data Source=damo.database.windows.net‌​;Initial Catalog=Ballinora_db; 
    Persist Security Info=True;
    User ID={Username};Password={Password};" /> </connectionStrings>

    Thanks a lot.

    Wednesday, February 15, 2017 7:51 PM

All replies

  • User-84896714 posted

    Hi damosull,

    damosull

    I know the username and password are correct, because I have used them to access the database previously in Microsoft SQL Server Management Studio.

    The password sometimes looks right. If there are some invisible characters behind your password, it will cause the error.

    For example, following 2 strings look same. But they have different length(the first one is 136 and the second one is 132) and if we use first one,  A error will popup which says “Login failed for user ‘amor’”.

    string cnnString = "Data Source=amor-sqlserver.database.windows.net;Initial Catalog=Amor-sqldb;Persist Security Info=True;User ID=amor;Password=password";
    string cnnString2 = "Data Source=amor-sqlserver.database.windows.net;Initial Catalog=Amor-sqldb;Persist Security Info=True;User ID=amor;Password=password";
    

    After copy your connection string to my side, I found there are 2 invisible characters after ".database.windows.net;". I copied "net;" and assign it to a string and executed following code.

    string content = "net;";
    Console.WriteLine("string length: " + content.Length);
    for (int i = 0; i < content.Length; i++)
    {
        Console.WriteLine(content[i] + "," + (int)content[i]);
    }
    

    Here was the result I got. We can see 8204 and 8203 characters between 't' and ';'. You could traverse all the characters in your connection string to check whether it contains invisible characters or not.

    string length: 6
    n,110
    e,101
    t,116
    ?,8204
    ?,8203
    ;,59
    

    Another reason which may cause the error is that the connection sting maybe changed during your publish process. Please check whether you have input the right connection string when you publish your website. You could valid the connection string by checking the remote Web.config file.

    Best Regards,
    Amor

    Monday, February 27, 2017 10:45 AM
  • User-84896714 posted

    Hi damosull,

    Is your issue solved? If you have further questions about it, please feel free to let me know.

    Best Regards,
    Amor

    Tuesday, February 28, 2017 5:42 AM