none
System.Data.SqlClient.SqlException:Login failed for user RRS feed

  • Question

  • Hi Team

    I am experince this issue close to a day and half now, no one seem to help. Basically i am using MVC to develop user registration to the dashboard. The problem is on my AuthConfig.cs under AppStart folder, here is my logic below;

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web;
    using Microsoft.Web.WebPages.OAuth;
    using WebMatrix.WebData;

    namespace eNtsaPortalWebsiteProject
    {
        public class AuthConfig
        {
            public static void RegisterAuth()
            {
                WebSecurity.InitializeDatabaseConnection("MyString", "Users", "UserName", "FullName", autoCreateTables: true);
            }
        }
    }

    Wednesday, January 22, 2020 8:33 AM

All replies

  • Hello,

    "MyString"

    You have SQL Server exception and didn't provide any information about SQL Server on which database are hosted.

    You also didn't provide suitable section with connection string from your config file to qualify "MyString".

    To have this working you require to have MS SQL Secver Compact and "MyString.sdf" database in Data folder.

    As an alternative - put the proper connection string instead of "MyString".


    Sincerely, Highly skilled coding monkey.

    Wednesday, January 22, 2020 9:38 AM
  • HI 

    This is my connection string on Web.Config

    <connectionStrings>
        <add name="Mystring" providerName="System.Data.SqlClient" connectionString="Data Source=Gcobanim-L\SQLEXPRESS;Database=eNtsaRegistrationDB" />
      </connectionStrings>

    Wednesday, January 22, 2020 10:15 AM
  • If there is no user name and password then add the following to your connection string

    <connectionStrings>
        <add name="Mystring" providerName="System.Data.SqlClient" connectionString="Data Source=Gcobanim-L\SQLEXPRESS;Database=eNtsaRegistrationDB;Trusted_Connection=Yes" />
    </connectionStrings>

    The following shows variations of connections strings

    https://www.connectionstrings.com/sql-server/


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, January 22, 2020 10:45 AM
    Moderator
  • Sorry, didn't get SQLEXPRESS working on my system at any time.

    Create small test project, create instance of SqlClient and get it connected to the database with your connection string. Modify string until didn't get connected.

    Then copy connection string to the config.

    Plus - check if you have required DLL's referenced in server or app configuration.


    Sincerely, Highly skilled coding monkey.

    Wednesday, January 22, 2020 11:01 AM
  • What i am trying to know, what could be reason for this exception? My local database runs on Windows authentication mode not on mix mode, could this be an impact? I am also using Websecurity assembly on my controllert to check for user validation and loop through session for each field. Here is the logic below maybe this could explain possible reason to this factor.

     [HttpPost]
            [AllowAnonymous]
            [ValidateAntiForgeryToken]
            public ActionResult Login(Login login)
            {
                if (ModelState.IsValid)
                {
                    bool success = WebSecurity.Login(login.username, login.password, false);
                    var UserID = GetUserID_By_UserName(login.username);
                    var LoginType = GetRoleBy_UserID(Convert.ToString(UserID));

                    if (success == true)
                    {
                        if (string.IsNullOrEmpty(Convert.ToString(LoginType)))
                        {
                            ModelState.AddModelError("Error", "Rights to User are not Provide Contact to Admin");
                            return View(login);
                        }
                        else
                        {
                            Session["Name"] = login.username;
                            Session["UserID"] = UserID;
                            Session["LoginType"] = LoginType;

                            if (Roles.IsUserInRole(login.username, "Admin"))
                            {
                                return RedirectToAction("AdminDashboard", "Dashboard");
                            }
                            else
                            {
                                return RedirectToAction("UserDashboard", "Dashboard");
                            }

                        }

                    }
                    else
                    {
                        ModelState.AddModelError("Error", "Please enter valid Username and Password");
                        return View(login);
                    }



                }
                else
                {
                    ModelState.AddModelError("Error", "Please enter Username and Password");
                    return View(login);
                }

            }

    That is why i end up granting permission using sql query, as shown above from the topic.


    • Edited by Gcobani2020 Wednesday, January 22, 2020 12:38 PM
    Wednesday, January 22, 2020 12:36 PM
  • >what could be reason for this exception?

    Because when you connect from IIS app you connect with credentials on which running IIS or site or service. Most likely this windows user not added as user to MS SQL. 



    Sincerely, Highly skilled coding monkey.

    Wednesday, January 22, 2020 1:48 PM
  • If your DB doesn't support SQL Auth then the only option you have is Windows auth and therefore you need to enable that as Karen indicated.

    However running a web app with Windows auth requires that either the app itself support Windows authentication or you must run the app pool under a Windows account that has access to the database. In this regard web apps work the same as services. You can post your questions related to authentication of web apps over in the ASP.NET forums though, not here.

    To work around your immediate problem, enable integrated security as Karen mentions and then ensure that your user account has access to that database. I'm assuming you're using IIS Express to test this code and therefore it will run against your user account. 

    Note also that SQL Express is effectively gone. If you're using VS 2015 or higher then you should be using the built in LocalDB that comes with VS. This won't change this situation in any way but it is easier and doesn't require a dependency on SQL Express.


    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, January 22, 2020 2:47 PM
    Moderator