SQL "Helper" issue  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

SQL "Helper" issue

Postby neil.interactit » Wed Jun 03, 2015 10:34 am

I have an issue I can't quite nail, with a Help I am developing to ease direct database access ...

USAGE:
Code: Select all
var taxCodes = PluginHelper.SqlDataTable("SELECT TaxID, Description FROM TX_Main ORDER BY Description");
foreach (DataRow row in taxCodes.Rows) BASCodeUltraComboEditor.Items.Add(row["TaxID"].ToString(), row["Description"].ToString());


HELPER:
Code: Select all
public static class PluginHelper
{
    public static DataTable SqlDataTable(string sql, SqlParameter[] paramList = null)
    {
        DataTable table = new DataTable();
        //try
        //{
        JiwaFinancials.Jiwa.JiwaODBC.database databaseObject = JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.Database;
        using (SqlCommand cmd = new SqlCommand(sql, databaseObject.SQLConnection, databaseObject.SQLTransaction))
        {
            if (paramList != null) cmd.Parameters.AddRange(paramList);
            cmd.Connection.Open();
            table.Load(cmd.ExecuteReader());
            cmd.Connection.Close();
        }
        //}
        //catch { }
        return table;
    }
}

(handling commented to see error)

ERROR:
The connection was not closed. The connection's current state is open. Module: TryOpenConnection

Can you point me in the right direction?

Cheers,
Neil
neil.interactit
Kohai
Kohai
 
Posts: 232
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6

Re: SQL "Helper" issue

Postby Mike.Sheen » Wed Jun 03, 2015 10:47 am

Hi Neil,

You're closing the Jiwa connection:

Code: Select all
cmd.Connection.Close();


Don't do that.

Mike
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: SQL "Helper" issue

Postby neil.interactit » Wed Jun 03, 2015 10:55 am

Thanks Mike,

I actually had just added that line in response to the "not closed" error. I have removed it again, but still get the same error.

Cheers,
Neil
neil.interactit
Kohai
Kohai
 
Posts: 232
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6

Re: SQL "Helper" issue  Topic is solved

Postby Scott.Pearce » Wed Jun 03, 2015 10:58 am

You shouldn't be opening the connection either.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 765
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 230

Re: SQL "Helper" issue

Postby neil.interactit » Wed Jun 03, 2015 11:26 am

That's got it ... do you need my postal address to forward on a dunce hat?
neil.interactit
Kohai
Kohai
 
Posts: 232
Joined: Wed Dec 03, 2014 2:36 pm
Topics Solved: 6

Re: SQL "Helper" issue

Postby Scott.Pearce » Wed Jun 03, 2015 11:31 am

lol
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 765
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 230


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 4 guests