version 6.3 CreateConnection example for MySQL db

User 873a9ae9d0

06-05-2014 11:16:43

Hi,

I just installed Chemaxon .Net API version 6.3. Now I want to setup a simple testprogram to do a fullstructure search in our Chemaxon db. The db is hosted in a MySQL db residing on a Windows 2012 server.

Could one send me an example of how to connect to a ChemAxon moltable in a MySQL db using the version 6.3  MainFactory.Database.CreateConnection method .


Most important: What do I specify as 'database' parameter ?


Can I use the IP address of the server as hostname ?


I assume the portnumber is the mysql port (default 3306) - correct?


 


Hope one can help.


Best regards
Hans-Juergen
AKos GmbH


 


 

ChemAxon 4375c6431d

07-05-2014 08:17:57

Hi Hans,


 


Yes, you can use the IP address of the server and you don't have to specify the port number if you use the default port ( = 3306 in case of MySQL).


database = catalog = a namespace within the server


This code example shows you how to perform a full structure search with MySQL database:


 


using ChemAxon.NET.IKVM.DB;


using ChemAxon.NET.API;


using ChemAxon.NET.IKVM.DB.Entities;


using ChemAxon.NET.IKVM.Chemistry;


using ChemAxon.NET.Base.Search.Options;


 


public void FullStructureSearchWithMySqlExample()


        {


            string host = "10.0.0.21";


            int port = 3306;


            string db = "JCHEMSQL_API_TEST";


            string userName = "jchem";


            string password = "jchem";


 


            //Connect to the database


            IConnectionInfo connection = MainFactory.Database.CreateConnection(host, port, db, userName, password, DBType.MySQL);


            string jchemPropertiesTable = "jchemProperties";


            IJChemDatabaseHandler database = MainFactory.Database.OpenJChem(connection, jchemPropertiesTable);


 


            //Get structure table from the database


            string structureTableName = "molecules";


            IEnumerable<IJChemTable> tables = database.GetTables();


            IJChemTable structureTable = tables.First(table => table.Name == structureTableName);


 


            //Create search parameter           


            IJChemMolecule queryMolecule = MainFactory.Chemistry.CreateMolecule("CCCC");


            IJChemMoleculeFilter filter = MainFactory.Database.CreateJChemMoleculeFilter(queryMolecule);


            filter.SearchOption.SearchType = JChemSearchTypes.Full;


 


            //Get filtered molecules


            IEnumerable<JChemDBMolecule> filterResult = structureTable.GetMolecules(filter);


 


            //Show results


            foreach (JChemDBMolecule molecule in filterResult)


            {


                Console.WriteLine(molecule.Formula);


            }


        }


 


Regards,


Miklos