I am developing an application in .Net and using .Net provider for TD. I have the code as below. I am selecting the session no, setting a queryband and running a query and setting the query band off. Few of the values are coming from my windows form textboxes. This code runs at the click of a button on my form.
I expect that once this block is executed once and connection is closed, and again the button is pressed, a new sessionid should be created. But i noticed that the sessionid remains the same for every run. Even on the viewpoint, the session persists. When the form is closed and opened afresh, and this button is pressed again, a new sessionid is generated. What is wrong here? I have coded one application in VBA using ODBC and it worked as expected. I went through the follwing post and as mentioned, i am using .Net connector for TD and not ODBC.This is very critical to my application as my basic premise is that every time a query is run, it runs with a different sessionid, hence any help is really appreciated.
public void Run_Originalquery()
conStringBuilder = new TdConnectionStringBuilder();
conStringBuilder.DataSource = "uat";
conStringBuilder.UserId = "test";
conStringBuilder.Password = "test";
o_queryband = my_query_band.Text.Trim();
using (tdCon = new TdConnection(conStringBuilder.ConnectionString))
o_my_query_text = "sel session;";
using (tdDA = new TdDataAdapter(o_my_query_text, tdCon))
// create the dataset
using (dsComp = new System.Data.DataSet())
int iSchemaCnt = dsComp.Tables["T_Database"].Rows.Count;
if (iSchemaCnt != 1)
//MessageBox.Show("Session Fetched Successfully!!");
o_sessionid = dsComp.Tables["T_Database"].Rows.ToString().
MessageBox.Show("Orig Session Fetched Successfully-" + o_sessionid);
using (TdCommand cmd = tdCon.CreateCommand())
cmd.CommandText = "SET QUERY_BAND ='query=" + my_query_band.Text.Trim() + ";' FOR SESSION;";
cmd.CommandText = query_to_run.Text.Trim();
o_query = query_to_run.Text.Trim();
MessageBox.Show("Original Query ran successfully!");
cmd.CommandText = "SET QUERY_BAND = NONE FOR SESSION;";
catch (Exception ex)
MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
I think i figured it out.You have to use - conStringBuilder.ConnectionPooling = false; in your connection string.
There is another post that is helpful for anyone facing similar issue.