no exception on DataContext.Connection.Open() ?

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
EeeeEfff
Posts: 15
Joined: Wed 26 Oct 2011 00:48

no exception on DataContext.Connection.Open() ?

Post by EeeeEfff » Wed 26 Oct 2011 20:26

Hi,
I am experiencing a strange problem, but maybe I'm doing something wrong.

Using the following snippet, if I pass an invalid connection string to my data context, I don't get an exception, nor an indication that the DataContext encountered any problems.

Code: Select all

    var ctxt = new MyDataContext(myConnectionString);
    ctxt.Connection.Open();
    ctxt.Connection.Close();
Using the following snippet (explicitly connecting using a MySqlConnection object), if I pass an invalid connection string to my data context, an exception does get thrown.

Code: Select all

    var connection = new MySqlConnection(myConnString);
    connection.Open();
    connection.Close();
So, without explicitly using the MySqlConnection API, how do I test that I have a valid connection to the database before proceeding to use my entity objects?

Any help would be appreciated.

Thanks,
E.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Thu 27 Oct 2011 10:30

We couldn't reproduce this problem in our environment. Could you please specify the following:
- the version of LinqConnect (or dotConnect for MySQL) you are using;
- what exactly is wrong in the connection string;
- what error message does the MySQL server return when you open the connection object cast to MySQLConnection.

EeeeEfff
Posts: 15
Joined: Wed 26 Oct 2011 00:48

Post by EeeeEfff » Thu 27 Oct 2011 21:00

Thanks for your response.

- the version of LinqConnect (or dotConnect for MySQL) you are using;
LinqConnect 3.0.10
- what exactly is wrong in the connection string;
Anything: incorrect user, password, host, etc..
- what error message does the MySQL server return when you open the connection object cast to MySQLConnection
Maybe I mis-stated the problem. I want an exception to be thrown. The problem is that I can pass junk to the data context as a connection string, call context.Connection.Open and Close and everything passes - no exception.
When I create a MySqlConnection and pass it a bogus connection string, upon calling Open(), I get the following exception, which is good:
A first chance exception of type 'System.InvalidOperationException' occurred in Devart.Data.MySql.dll
Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.

My connection string in this case is below:
User Id=root;Password=mysql;Host=localhost;Database=blah

If I pass this connection string to the data context constructor, call context.Connection.Open and Close and everything passes - no exception. That's the problem.

I can do my test explicitly using the MySqlConnection object, and that detects invalid logins/schema/host/etc., but I don't understand why connecting with the DataContext is passing the connection.Open, despite being provided a connection string with invalid logins/schema/host/etc..

Thanks.
E.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Fri 28 Oct 2011 12:58

In our environment, we are getting the same invalid operation exception when trying to open the data context connection with an invalid connection string. Could you please check the following:
- the preliminary exceptions being thrown when opening a connection explicitly cast to MySqlConnection;
- whether any exceptions are thrown and caught when opening the context connection.
To see these preliminary exceptions, please run your sample under debug and enable the 'Common Language Runtime Exceptions' check box in the Exceptions dialog (the Debug -> Exceptions item of the Visual Studio main menu).

Please tell us about the results.

EeeeEfff
Posts: 15
Joined: Wed 26 Oct 2011 00:48

Post by EeeeEfff » Fri 28 Oct 2011 17:26

Before making any changes, I tried running this morning and did not get the exception. So that's the problematic behavior that I had been observing.

In the debugger, user-unhandled CLR exceptions were already enabled. I turned on the other checkbox too so that all thrown CLR exceptions are triggered. All of a sudden, I started getting the exception. So then I turned off the "all thrown CLR exceptions" checkbox, going back to the original setting, and the exception continued to come up!

Is there something in the context that gets cached in some file somewhere that wasn't getting cleared?

This is really weird.

Thanks,
E.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Mon 31 Oct 2011 08:19

Glad to see that the problem was resolved. Feel free to contact us if you encounter any other problems when working with LinqConnect.

The DataContext class does not store any parameters or connection-related information on the disk.

Post Reply