Hi,
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.
https://forums.teradata.com/forum/connectivity/connections-created-w-odbc-net-are-surviving-after-conn-close
--Samir Singh
public void Run_Originalquery() { string o_my_query_text; TdConnectionStringBuilder conStringBuilder; TdConnection tdCon; TdDataAdapter tdDA; DataSet dsComp; 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)) { try { tdCon.Open(); o_my_query_text = "sel session;"; using (tdDA = new TdDataAdapter(o_my_query_text, tdCon)) { // create the dataset using (dsComp = new System.Data.DataSet()) { tdDA.Fill(dsComp, "T_Database"); int iSchemaCnt = dsComp.Tables["T_Database"].Rows.Count; if (iSchemaCnt != 1) { MessageBox.Show("Something strange"); } else { //MessageBox.Show("Session Fetched Successfully!!"); o_sessionid = dsComp.Tables["T_Database"].Rows[0][0].ToString().Trim(); 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.ExecuteNonQuery(); cmd.CommandText = query_to_run.Text.Trim(); cmd.ExecuteNonQuery(); o_query = query_to_run.Text.Trim(); MessageBox.Show("Original Query ran successfully!"); cmd.CommandText = "SET QUERY_BAND = NONE FOR SESSION;"; cmd.ExecuteNonQuery(); } tdCon.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); //Application.Exit(); } } }