Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
public bool getSessions()
{
string S = comboBox1.Text.ToString();
try
C#


{

string query = "SELECT 'ALTER SYSTEM KILL SESSION ' || '''' || sid || ',' || serial# || '''' ||' IMMEDIATE; ' KILL_IT, username, status, schemaname, module, osuser, program, action, logon_time, s.sid," +
" s.SERIAL# " + "FROM v$session s " + "WHERE s.status <> 'KILLED' and upper(s.username) like upper('%" + comboBox1.Text.Trim() + "%') " +
"order by s.username, s.logon_time";

using (OracleConnection con = new OracleConnection(conString))
{
con.Open();
OracleCommand cmd = con.CreateCommand();
cmd.CommandText = query;


using (var reader = cmd.ExecuteReader())
{
DataTable dt = new DataTable();

OracleDataAdapter da = new OracleDataAdapter(cmd);
da.Fill(dt);
DataTable tempDT = new DataTable();
tempDT = dt.DefaultView.ToTable(true, "KILL_IT", "USERNAME", "SCHEMANAME", "OSUSER", "PROGRAM", "LOGON_TIME");
dataGridView1.DataSource = tempDT;

}

con.Close();
return true;
}

}
catch (Exception ex)
{
MessageBox.Show(ex.HResult.ToString());
MessageBox.Show(ex.Message);
return false;
}
}

What I have tried:

have problem
value cannot be null parameter name key?in c# 
Posted
Updated 7-Jan-20 10:24am

The debugger will be your friend here. Have you stepped through to determine where the error is occurring?
At a glance, I suspect an issue here. Where is conString declared?
using (OracleConnection con = new OracleConnection(conString))
 
Share this answer
 
Comments
Member 14709678 7-Jan-20 14:56pm    
whats problem?
Kris Lantz 7-Jan-20 15:00pm    
From the code provided above, conString is not declared, meaning the new OracleConnection(conString) will not process, because it is null. The connection will never be opened to the DB.
Once you fix your connection string, fix the SQL INJECTION vulnerability
C#
string query = "SELECT 'ALTER SYSTEM KILL SESSION ' || '''' || sid || ',' || serial# || '''' ||' IMMEDIATE; ' KILL_IT, username, status, schemaname, module, osuser, program, action, logon_time, s.sid," +
" s.SERIAL# " + "FROM v$session s " + "WHERE s.status <> 'KILLED' and upper(s.username) like upper('%" + comboBox1.Text.Trim() + "%') " +
"order by s.username, s.logon_time";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900