google-code-export / dblinq2007

Automatically exported from code.google.com/p/dblinq2007
Other
0 stars 0 forks source link

[Enhancement] Datacontext constructor using connection string is not working #243

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
After generating the class e.g. 'Customers' with DBMetal, you cannot use

Customers custDB = new Customers(customersConnectionString)

instead you have to open up a new DBConnection and pass it as the parameter 
to the DataContext constructor.

Original issue reported on code.google.com by tzograp...@gmail.com on 17 Apr 2010 at 10:57

GoogleCodeExporter commented 9 years ago
Can you elaborate? Is Customers an entity type or your DataContext subclass?

If it's the former, entity types aren't supposed to have constructors which 
take 
string or IDbConnection parameters.

If it's the latter, what error are you getting?  The unit tests use the 
constructor 
which accepts a string parameter, not the IDbConnection overload.

Original comment by jonmpr...@gmail.com on 18 Apr 2010 at 1:54

GoogleCodeExporter commented 9 years ago
It's the latter. I am using the class that inherits from DataContext directly.
Please not that I am using MySQL.

Code #1 (NOT WORKING)

string connectionString 
= "Server=localhost;User=MyUser;Password=MyPass;Database=MyDB;Use 
Compression=True;Connection Protocol=Sockets";

using (Customer custDB = new Customer(connectionString))
{
....
}

Code #2 (WORKS CORRECTLY)

string connectionString 
= "Server=localhost;User=MyUser;Password=MyPass;Database=MyDB;Use 
Compression=True;Connection Protocol=Sockets";
using (Customer custDB=new Customer( new MySqlConnection(connectionString)))
{
...
}

The connectionStrings in #1 and #2 are the same. All the code is the same, 
except 
the using(...) command.

The error I get in the #1 case is
"Unable to load the `DbLinq.SqlServer' DbLinq vendor within assembly 
'SqlServer.dll'.
Parameter name: connectionString"

Please note again that I am using MySQL.

From the metadata of DataContext class I see a [DBLinqToDo] attribute on top 
the 
DataContext constructor.

        [DbLinqToDo]
        public DataContext(string connectionString);

Original comment by tzograp...@gmail.com on 19 Apr 2010 at 1:18

GoogleCodeExporter commented 9 years ago
See: http://code.google.com/p/dblinq2007/wiki/Installation#To_use_DbLinq

Specifically, you need to provide the DbLinqConnectionType and DbLinqProvider 
key/value pairs in your connection string.  If you don't provide these, DbLinq 
defaults to Microsoft SQL Server types.

Original comment by jonmpr...@gmail.com on 19 Apr 2010 at 2:32