The underlying provider failed on Open

I made 3 Ajax processes to run the below code at the same time.
but one of the processes throw exception that message says “The underlying provider failed on Open.”

try{
    orderRepository orderRepo = new orderRepository(); // get context (Mysql)

    var result = (from x in orderRepo.orders
          where x.orderid == orderno
          select new {x.tracking, x.status, x.charged }).SingleOrDefault();

    charged = result.charged;
}catch(Exception e){
    log.Error(e.Message); //    The underlying provider failed on Open.
}

And, I run the 1 Ajax call that failed before, then It passes through.

It happen to 1 of 3 (Ajax) process, sometimes, 2 of 5 process.

I guess it because all process try to using Database same time. but I couldn’t find the solution.

This is my connection string,

<add name="EFMysqlContext" connectionString="server=10.0.0.10;User Id=root;pwd=xxxx;Persist Security Info=True;database=shop_db" providerName="Mysql.Data.MySqlClient" />

Anybody know the solution or something I can try, please advise me.

Thanks

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

It sounds like a problem because of concurrent connection with SQL Server using same username. Have you tried destroying/disposing the repository(or connection) object after using it?
Give it a try:

 try{
       using( orderRepository orderRepo = new orderRepository()) // get context (Mysql)
        {
          var result = (from x in orderRepo.orders
              where x.orderid == orderno
              select new {x.tracking, x.status, x.charged }).SingleOrDefault();

        charged = result.charged;
    } // orderRepo object automatically gets disposed here
catch(Exception e){
        log.Error(e.Message); //    The underlying provider failed on Open.
    } }

Method 2

Not sure if it matters, but your provider name is Mysql.Data.MySqlClient and not MySql.Data.MySqlClient (if it is case-sensitive, this could be the cause).


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x