Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure when executing SQL string #7

Closed
hcusto opened this issue Jun 13, 2014 · 6 comments
Closed

Failure when executing SQL string #7

hcusto opened this issue Jun 13, 2014 · 6 comments

Comments

@hcusto
Copy link

hcusto commented Jun 13, 2014

I'm trying to use ReliableDbProvider with EF 5. and I'm unable to execute hand written sql query. Here is failing test

public void Insert_and_select_entity()
    {
        using (var context = GetContext())
        using (var context2 = GetContext())
        {
            var user = new User { Name = "Name" };
            context.Users.Add(user);
            context.SaveChanges();

            var dbUser = context2.Database.SqlQuery<User>("select * from users where Id = '" + user.Id + "'").FirstOrDefault();

            Assert.That(dbUser.Name, Is.EqualTo(user.Name));
        }
    }

here is part that breaks Test

var dbUser = context2.Database.SqlQuery<User>("select * from users where Id = '" + user.Id + "'").FirstOrDefault();

Error is inside ReliableSqlCommand

  protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
        {
          //ReliableConnection is null
            return ReliableConnection.CommandRetryPolicy.ExecuteAction(() => {
                if (Connection == null)
                    Connection = ReliableConnection.Open();
                if (Connection.State != ConnectionState.Open)
                    Connection.Open();
                return Current.ExecuteReader(behavior);
            });
        } 

@robdmoore
Copy link
Member

Hey mate,

I didn't get a chance to look at this over the weekend - was busy repaving my machine.

Will try and look sometime this week.

@hcusto
Copy link
Author

hcusto commented Jun 15, 2014

Hi Rob, thanks for heads up.

@robdmoore robdmoore changed the title Failing test Failure when executing SQL string Jun 22, 2014
robdmoore added a commit that referenced this issue Jun 22, 2014
@robdmoore
Copy link
Member

Hey,

I've started taking a look at this. I've got a WIP pull request up with failing tests - I can confirm this is a problem.

Off the top of my head I don't know why it's not using the reliable connection - it seems to be bypassing the proxy code somehow. This stuff is super, super complex and it's been quite a while since I've had my head into it so to be honest it might take me a while to figure it out.

cc @MattDavies

BlairAllegroTech added a commit to BlairAllegroTech/ReliableDbProvider that referenced this issue Jul 6, 2014
@BlairAllegroTech
Copy link
Contributor

The reason for this code failing was that the "ReliableConnection" of the Command was not being set in the constructor when the ReliableSqlDbComand was being constructed with a command that already has an associated Connection. To overcome this issue i have added a second constructor that take as SQLCommand and a ReliableSqlDbConnection (Which is just the wrapped version of the existing commands connection.

    //Bug Fix: Failure when executing SQL string
    public ReliableSqlCommand(ReliableSqlDbConnection connection, SqlCommand commandToWrap) 
    {
        this.Current = commandToWrap;
        this.ReliableDbConnection = connection;
        this.ReliableConnection = (connection==null) ? null : connection.ReliableConnection;
    } 

@robdmoore
Copy link
Member

Awesome! Thanks for finding the problem :)

I'll take a look over the next week and get the code in!

@robdmoore
Copy link
Member

@hcusto this problem should be fixed in the next version of ReliableDbProvider. I'll let you know when it's released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants