RepoDB: Bug: ExecuteQueryMultiple/Extract is throwing SqlException: Login failed for user

Am I using ExecuteQueryMultiple / Extract incorrectly here or there is a bug?

var sql1 = @"SELECT * FROM UsersTbl;";
var sql2 = @"SELECT * FROM RolesTbl;";
var sql3 = @"SELECT * FROM UserXRoleTbl;";

using var connection = await new SqlConnection(connectionString).EnsureOpenAsync().ConfigureAwait(false);
//WORKS FINE
var users = await connection.ExecuteQueryAsync<User>(sql1).ConfigureAwait(false);
var roles = await connection.ExecuteQueryAsync<Role>(sql2).ConfigureAwait(false);
var userXRoles = await connection.ExecuteQueryAsync<UserXRole>(sql3).ConfigureAwait(false);

//FAILS
using var results = await connection.ExecuteQueryMultipleAsync($"{sql1}{sql2}{sql3}").ConfigureAwait(false);
var users = await results.ExtractAsync<User>().ConfigureAwait(false); //THROWS SqlException: Login failed for user <username>
var roles = await results.ExtractAsync<Role>().ConfigureAwait(false);
var userXRoles = await results.ExtractAsync<UserXRole>().ConfigureAwait(false);

From what I understand ExecuteQueryMultiple runs all queries in one trip hence I would prefer it over individual ExecuteQuery’s.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 21 (21 by maintainers)

Commits related to this issue

Most upvoted comments

This is now available at RepoDb v1.12.0.

I’m glad if I helped, I really like this project. I plan to use it in my next project so it must work well 😃. I think I found another problem after I stripped EnsureOpenAsync(). I will describe in separate thread.

This library is a buggy library before, a lot has changed and a lot has been covered with Integration and Unit Tests. I could not even pin point the changes made that fixed this, but I am sure of what the code written as of today’s date. 😄

Actually, you’re right, now when I check I don’t have to manually EnsureOpen()! I remember my first encounter with RepoDB was that it was failing until I checked docs and figured out I must call EnsureOpen(). Can’t tell now what the method was.

No, I do not close the connection. In fact, just before ExtractAsync it is still open. Here’s my complete use:

var sql1 = @"SELECT * FROM UsersTbl;";
var sql2 = @"SELECT * FROM RolesTbl;";
var sql3 = @"SELECT * FROM UserXRoleTbl;";
            
using (var connection = await new SqlConnection(connectionString).EnsureOpenAsync().ConfigureAwait(false))
{
    using (var results = await connection.ExecuteQueryMultipleAsync($"{sql1}{sql2}{sql3}").ConfigureAwait(false))
    {
        Debug.Print(connection.State.ToString()); // Prints "Open"
        var users = await results.ExtractAsync<User>().ConfigureAwait(false); // FAILS
        var roles = await results.ExtractAsync<Role>().ConfigureAwait(false);
        var userXRoles = await results.ExtractAsync<UserXRole>().ConfigureAwait(false);

        foreach (var u in users)
        {
            /// ... 
        }

        return users;
    }
}

Just checked synchronous methods for this scenario and it throws the same error in the same place.