ConnectionHandler is not connected error

User 761d9eb85b

12-11-2015 03:27:44

Hello,


I am testing the JChemBaseSearch example of ChemAxon.NET 15.11.200.349.


I change the connection string to Ms sql server and made following change:


using (IJChemDatabaseHandler db = MainFactory.Database.OpenJChem(MainFactory.Database.CreateConnection(host, port, database, username, password, DBType.MSSQL)))


The connection is well established. But an exception is thrown at following line of code:


var transformedDataTable = searchResults.ToDataTable("cd_structure");


An unhandled exception of type 'java.lang.IllegalArgumentException' occurred in ChemAxon.IKVM.aloe.1.0-ikvm-runtime-injected
Additional information: ConnectionHandler is not connected.


Then I tested with Oracle database but got the same exception.


Could you tell me how to make it work?


Thank you very much!


Ning

ChemAxon 2e7d8629fa

12-11-2015 13:31:31

 


 Hello,


 


Could you describe what is the object "searchResult" and how did you get that? Could you give me a code snippet to illustrate what your code does after the DB connection is established?


 


Thank you.


Best regards,


Gergely

User 761d9eb85b

13-11-2015 01:09:28

Hi,


This is the official example downloaded from


https://www.chemaxon.com/download/marvin-suite/#mdotnet


Here are the two functions called after search button clicked.


public static IEnumerable<JChemDBMolecule> SearchStructure(IJChemMoleculeFilter moleculeFilter)
        {
            string host = ConfigurationManager.AppSettings["host"];
            string database = ConfigurationManager.AppSettings["database"];
            int port = Int32.Parse(ConfigurationManager.AppSettings["port"]);
            string username = ConfigurationManager.AppSettings["username"];
            string password = ConfigurationManager.AppSettings["password"];

            using (IJChemDatabaseHandler db = MainFactory.Database.OpenJChem(MainFactory.Database.CreateConnection(host, port, database, username, password, DBType.Oracle)))
            {
                string tablename = ConfigurationManager.AppSettings["tablename"];
                //IJChemTable table = db.GetTables().First(tbl => string.Equals(tbl.Name, tablename, StringComparison.InvariantCultureIgnoreCase));
                IJChemTable table = db.GetEntity(tablename);

                if (moleculeFilter != null)
                    return table.GetMolecules(moleculeFilter);
                else
                    return table.GetMolecules();
            }
        }


private void searchDatabaseBtn_Click(object sender, EventArgs e)
        {
            btnSearch.Enabled = false;

            try
            {                                                
                //to do: run it on a separate thread
                IEnumerable<JChemDBMolecule> searchResults = DataAccess.SearchStructure(_moleculeFilter);

                var transformedDataTable = searchResults.ToDataTable("cd_structure");
                searchResultsGridView.MoleculeColumns.Clear();
                searchResultsGridView.MoleculeColumns.Add("cd_structure");
                searchResultsGridView.DataSource = transformedDataTable;
            }
            finally
            {
                btnSearch.Enabled = true;
            }
        }


Thank you for your help!


Ning

ChemAxon 2e7d8629fa

13-11-2015 15:45:23

 


 Hello,


 


The using block causes the problem in the SearchStructure function. After this block the IJChemDatabaseHandler instance will be disposed and the underlying connection will be closed. Try to call Dispose() on IJChemDatabaseHandler after the datatable transformation (ToDataTable).



I hope it helps.


 


Best regards,


Gergely

User 761d9eb85b

16-11-2015 06:40:49

Thank you! It works now.


Best regards,


Ning