1

While connecting to SQL Server using Dapper ORM, I'm getting this error:

Login failed for user 'ttest'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'ttest'.

Source Error:

Line 40: using (SqlConnection sqlCon = new SqlConnection(connectionString))
Line 41: {
Line 42: sqlCon.Open();
Line 43: return sqlCon.Query(procedureName, param, commandType: CommandType.StoredProcedure);
Line 44: }

Line 42 is shown as an error

Code is

using Dapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

namespace DapperMVC.Models
{
    public class DapperORM
    {
        private static string connectionString = @"Data Source = test01\itest;Initial Catalog = SubbuDB; Persist Security Info=True;User ID = esiinttest; Password=***********;";

        public static void ExecuteWithoutReturn(string procedureName, DynamicParameters param = null)
        {
            using (SqlConnection sqlCon = new SqlConnection(connectionString))
            {
                sqlCon.Open();
                sqlCon.Execute(procedureName, param, commandType: CommandType.StoredProcedure);
            }
        }

        //DapperORM.ExecuteReturnScalar<int>(_,_);
        public static T ExecuteReturnScalar<T>(string procedureName, DynamicParameters param = null)
        {
            using (SqlConnection sqlCon = new SqlConnection(connectionString))
            {
                sqlCon.Open();
                return (T)Convert.ChangeType(sqlCon.ExecuteScalar(procedureName, param, commandType: CommandType.StoredProcedure), typeof(T));
            }
        }

        //DapperORM.ReturnList<EmployeeModel> <=  IEnumerable<EmployeeModel>
        public static IEnumerable<T> ReturnList<T>(string procedureName, DynamicParameters param = null)
        {
            using (SqlConnection sqlCon = new SqlConnection(connectionString))
            {
                sqlCon.Open();
                return sqlCon.Query<T>(procedureName, param, commandType: CommandType.StoredProcedure);
            }
        }
    }
}

1 Answer 1

2

When SQL Server is installed using Windows Authentication mode and is later changed to SQL Server and Windows Authentication mode, the ttest login is initially disabled.To enable the ttest login, see How to: How to: Change Server Authentication Mode.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.