LinqConnect Professional Version 4.4.374 (14-Nov-2013) - Connect to MySQl without Database Name

LinqConnect Professional Version 4.4.374 (14-Nov-2013) - Connect to MySQl without Database Name

Postby AKRRKA » Wed 04 Dec 2013 15:18

When open connection to MySQL without set database name, don`t get exception.

Connection string example:
Code: Select all
user id=ceadmin;password=***********;host=10.5.56.177;unicode = True;persist security info=True;Pooling=False;found rows=True


Code:
Code: Select all
private void ComandConnectionOpen()
{
    try
    {

        Stream contextStream =
            Assembly.GetExecutingAssembly()
                    .GetManifestResourceStream("ceDataSource.Model.ceDataContext" + ProviderPrefix + ".xml");
        MappingSource mappingSource = XmlMappingSource.FromStream(contextStream);
        DataContext = new ceDataContext(ConnectionString, mappingSource);

        DataContext.Connection.Open();

   MessageBox.Show("Database connected!");
    }
    catch (Exception exception)
    {

   MessageBox.Show("Error!" + exception.Message);
    }
}
AKRRKA
 
Posts: 194
Joined: Thu 26 Jan 2012 15:07
Location: Russia

Re: LinqConnect Professional Version 4.4.374 (14-Nov-2013) - Connect to MySQl without Database Name

Postby MariiaI » Thu 05 Dec 2013 11:43

When open connection to MySQL without set database name, don`t get exception

This is a normal behavior. The connection opens to the MySQL server with the necessary credentials (user and password). After the connection is opened:
- if the the schema name is preserved (the "Preserve schema name in storage" check box is selected in the Model Settings) and the mapping contains table name such as, e.g. "test.table_name", the data is retrieved from the table in the "test" database;
- if not, you will get the "No database selected" error.
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: LinqConnect Professional Version 4.4.374 (14-Nov-2013) - Connect to MySQl without Database Name

Postby AKRRKA » Fri 06 Dec 2013 04:36

MariiaI wrote:
When open connection to MySQL without set database name, don`t get exception

This is a normal behavior. The connection opens to the MySQL server with the necessary credentials (user and password). After the connection is opened:
- if the the schema name is preserved (the "Preserve schema name in storage" check box is selected in the Model Settings) and the mapping contains table name such as, e.g. "test.table_name", the data is retrieved from the table in the "test" database;


In my model the "Preserve schema name in storage" check box is NOT selected.

MariiaI wrote:- if not, you will get the "No database selected" error.


And don`t get error.
AKRRKA
 
Posts: 194
Joined: Thu 26 Jan 2012 15:07
Location: Russia

Re: LinqConnect Professional Version 4.4.374 (14-Nov-2013) - Connect to MySQl without Database Name

Postby MariiaI » Fri 06 Dec 2013 06:22

The error occurs when data is retrieved, not when connection is opened. Please check that your mapping file ("ceDataSource.Model.ceDataContext" + ProviderPrefix + ".xml") doesn't include schema names in the table names.
Please try retrieving data after you have opened the connection:
Code: Select all
new ceDataContext(ConnectionString, mappingSource);
DataContext.Connection.Open();
MessageBox.Show("Database connected!");
var data = DataContext.SomeTable.ToList();

Also, we have sent you a sample project to the e-mail address you have provided in your forum profile. Please check that the letter is not blocked by your mail filter. Please test it and tell us about the results.
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: LinqConnect Professional Version 4.4.374 (14-Nov-2013) - Connect to MySQl without Database Name

Postby AKRRKA » Fri 06 Dec 2013 10:58

MariiaI wrote:The error occurs when data is retrieved, not when connection is opened. Please check that your mapping file ("ceDataSource.Model.ceDataContext" + ProviderPrefix + ".xml") doesn't include schema names in the table names.


Really name of the database file is written, but why if in model the "Preserve schema name in storage" check box is NOT selected?

MariiaI wrote:Please try retrieving data after you have opened the connection:
Code: Select all
new ceDataContext(ConnectionString, mappingSource);
DataContext.Connection.Open();
MessageBox.Show("Database connected!");
var data = DataContext.SomeTable.ToList();

Also, we have sent you a sample project to the e-mail address you have provided in your forum profile. Please check that the letter is not blocked by your mail filter. Please test it and tell us about the results.


Yes it work and get error.
AKRRKA
 
Posts: 194
Joined: Thu 26 Jan 2012 15:07
Location: Russia

Re: LinqConnect Professional Version 4.4.374 (14-Nov-2013) - Connect to MySQl without Database Name

Postby MariiaI » Tue 10 Dec 2013 13:59

Really name of the database file is written, but why if in model the "Preserve schema name in storage" check box is NOT selected?
Most likely, you've created the LinqConnect model earlier with the selected "Preserve schema name in storage" check box and generated the corresponding xml mapping file with schema names. Later, you clear this check-box and save the changes - in this case these changes will not affect the storage part and the mapping. In order to changes become effective for all Entity classes, it is necessary to select "Regenerate Storage and Mapping" from the diagram shortcut menu or use the "Update Model from Database" wizard with the selected "Recreate Model" option.

If you are talking about this code:
Code: Select all
<Database Name="Test_DB" Provider="Devart.Data.MySql.Linq.Provider.MySqlDataProvider, Devart.Data.MySql.Linq"
xmlns="http://schemas.devart.com/linqconnect/mapping">
it isn't related to this scenario. In such cases Database Name is used only in CreateDatabase/DatabaseExists/DeleteDatabase methods.
If the mapping looks like this (see below) and the database name is not specified in the connection string, you will get the error that database was not selected:
Code: Select all
<Database Name="Test_DB" Provider="Devart.Data.MySql.Linq.Provider.MySqlDataProvider, Devart.Data.MySql.Linq" xmlns="http://schemas.devart.com/linqconnect/mapping">
  <Table Name="Companies" Member="Companies">
    ...
  </Table>
  <Table Name="Customers" Member="Customers">
    ...
  </Table>
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17


Return to LinqConnect (LINQ to SQL support)