connection closed when using cursor and procedure











up vote
0
down vote

favorite












My code is-



        string oracleb = "Data source=HPPRO58; user ID=system; password=deb;";
conn = new OracleConnection(oracleb);
//conn.Open();
conn.Open();
String x3 = "google";
String x1 ;
String x2;
String s1 = "delete from temp";
OracleCommand comm = new OracleCommand(s1, conn);
comm.ExecuteNonQuery();


OracleCommand comm2 = new OracleCommand();
String s2 = "cv";
comm2.Connection = conn;
comm2.CommandText = s2;
comm2.CommandType = CommandType.StoredProcedure;
comm2.Parameters.Add("x", System.Data.OracleClient.OracleType.Number).Value = comboBox1.Text;
comm2.Parameters.Add("y", System.Data.OracleClient.OracleType.Number).Value = comboBox2.Text;
comm2.Parameters.Add("z", System.Data.OracleClient.OracleType.Number).Value = x3;
comm2.ExecuteNonQuery();

String s3 = "select * from temp";
OracleCommand comm3 = new OracleCommand(s3, conn);
OracleDataAdapter MyAdapter3 = new OracleDataAdapter();//adapter acts as interface btw database and dataset(which is collectio of tables)
MyAdapter3.SelectCommand = comm;
DataTable dTable3 = new DataTable();//datatable represents a single table in database
MyAdapter3.Fill(dTable3);
dataGridView1.DataSource = dTable3;
conn.Close();


My error is-



enter image description here



I am trying to run a procedure which has a cursor too.Therefore I am using 3 comm variables.But I am getting the above error.Therefore I was wondering how to solve it.



I have opened the connection in the starting of the function but still it is showing connection is closed.



edit-



my procedure name is cv



new error-
enter image description here



my procedure-



create or replace procedure cv(x in int,y in int,z in varchar)
as
cursor c
is
select email,collegename,cgpa,compname
from student_cv
where (cgpa>=x and yearsofexp>=y) and compname=z;
tem c%rowtype;
begin
open c;
loop
fetch c into tem;
exit when c%notfound;
insert into temp values(tem.email,tem.collegename,tem.cgpa,tem.compname);
end loop;
end;
/


line 59 is-



comm2.Parameters.Add("x", System.Data.OracleClient.OracleType.Number).Value = comboBox1.Text;









share|improve this question
























  • I see your comm and comm3 are using the conn but your comm2 and comm3 I dont see you setting the conn to use anywhere?
    – Brad
    Nov 9 at 20:07












  • Well spotted. That must be the culprit.
    – johey
    Nov 9 at 20:16










  • @Brad I did some changes and got new errors. line 59 is comm2.Parameters.Add("x", System.Data.OracleClient.OracleType.Number).Value = comboBox1.Text;
    – ubuntu_noob
    Nov 9 at 20:21










  • I dont think your using paramaters right, you need to put the paramater name in the text and set the value by using the paramanter set look here docs.microsoft.com/en-us/dotnet/api/…
    – Brad
    Nov 9 at 20:32










  • @Brad I have added the procedure
    – ubuntu_noob
    Nov 9 at 20:34















up vote
0
down vote

favorite












My code is-



        string oracleb = "Data source=HPPRO58; user ID=system; password=deb;";
conn = new OracleConnection(oracleb);
//conn.Open();
conn.Open();
String x3 = "google";
String x1 ;
String x2;
String s1 = "delete from temp";
OracleCommand comm = new OracleCommand(s1, conn);
comm.ExecuteNonQuery();


OracleCommand comm2 = new OracleCommand();
String s2 = "cv";
comm2.Connection = conn;
comm2.CommandText = s2;
comm2.CommandType = CommandType.StoredProcedure;
comm2.Parameters.Add("x", System.Data.OracleClient.OracleType.Number).Value = comboBox1.Text;
comm2.Parameters.Add("y", System.Data.OracleClient.OracleType.Number).Value = comboBox2.Text;
comm2.Parameters.Add("z", System.Data.OracleClient.OracleType.Number).Value = x3;
comm2.ExecuteNonQuery();

String s3 = "select * from temp";
OracleCommand comm3 = new OracleCommand(s3, conn);
OracleDataAdapter MyAdapter3 = new OracleDataAdapter();//adapter acts as interface btw database and dataset(which is collectio of tables)
MyAdapter3.SelectCommand = comm;
DataTable dTable3 = new DataTable();//datatable represents a single table in database
MyAdapter3.Fill(dTable3);
dataGridView1.DataSource = dTable3;
conn.Close();


My error is-



enter image description here



I am trying to run a procedure which has a cursor too.Therefore I am using 3 comm variables.But I am getting the above error.Therefore I was wondering how to solve it.



I have opened the connection in the starting of the function but still it is showing connection is closed.



edit-



my procedure name is cv



new error-
enter image description here



my procedure-



create or replace procedure cv(x in int,y in int,z in varchar)
as
cursor c
is
select email,collegename,cgpa,compname
from student_cv
where (cgpa>=x and yearsofexp>=y) and compname=z;
tem c%rowtype;
begin
open c;
loop
fetch c into tem;
exit when c%notfound;
insert into temp values(tem.email,tem.collegename,tem.cgpa,tem.compname);
end loop;
end;
/


line 59 is-



comm2.Parameters.Add("x", System.Data.OracleClient.OracleType.Number).Value = comboBox1.Text;









share|improve this question
























  • I see your comm and comm3 are using the conn but your comm2 and comm3 I dont see you setting the conn to use anywhere?
    – Brad
    Nov 9 at 20:07












  • Well spotted. That must be the culprit.
    – johey
    Nov 9 at 20:16










  • @Brad I did some changes and got new errors. line 59 is comm2.Parameters.Add("x", System.Data.OracleClient.OracleType.Number).Value = comboBox1.Text;
    – ubuntu_noob
    Nov 9 at 20:21










  • I dont think your using paramaters right, you need to put the paramater name in the text and set the value by using the paramanter set look here docs.microsoft.com/en-us/dotnet/api/…
    – Brad
    Nov 9 at 20:32










  • @Brad I have added the procedure
    – ubuntu_noob
    Nov 9 at 20:34













up vote
0
down vote

favorite









up vote
0
down vote

favorite











My code is-



        string oracleb = "Data source=HPPRO58; user ID=system; password=deb;";
conn = new OracleConnection(oracleb);
//conn.Open();
conn.Open();
String x3 = "google";
String x1 ;
String x2;
String s1 = "delete from temp";
OracleCommand comm = new OracleCommand(s1, conn);
comm.ExecuteNonQuery();


OracleCommand comm2 = new OracleCommand();
String s2 = "cv";
comm2.Connection = conn;
comm2.CommandText = s2;
comm2.CommandType = CommandType.StoredProcedure;
comm2.Parameters.Add("x", System.Data.OracleClient.OracleType.Number).Value = comboBox1.Text;
comm2.Parameters.Add("y", System.Data.OracleClient.OracleType.Number).Value = comboBox2.Text;
comm2.Parameters.Add("z", System.Data.OracleClient.OracleType.Number).Value = x3;
comm2.ExecuteNonQuery();

String s3 = "select * from temp";
OracleCommand comm3 = new OracleCommand(s3, conn);
OracleDataAdapter MyAdapter3 = new OracleDataAdapter();//adapter acts as interface btw database and dataset(which is collectio of tables)
MyAdapter3.SelectCommand = comm;
DataTable dTable3 = new DataTable();//datatable represents a single table in database
MyAdapter3.Fill(dTable3);
dataGridView1.DataSource = dTable3;
conn.Close();


My error is-



enter image description here



I am trying to run a procedure which has a cursor too.Therefore I am using 3 comm variables.But I am getting the above error.Therefore I was wondering how to solve it.



I have opened the connection in the starting of the function but still it is showing connection is closed.



edit-



my procedure name is cv



new error-
enter image description here



my procedure-



create or replace procedure cv(x in int,y in int,z in varchar)
as
cursor c
is
select email,collegename,cgpa,compname
from student_cv
where (cgpa>=x and yearsofexp>=y) and compname=z;
tem c%rowtype;
begin
open c;
loop
fetch c into tem;
exit when c%notfound;
insert into temp values(tem.email,tem.collegename,tem.cgpa,tem.compname);
end loop;
end;
/


line 59 is-



comm2.Parameters.Add("x", System.Data.OracleClient.OracleType.Number).Value = comboBox1.Text;









share|improve this question















My code is-



        string oracleb = "Data source=HPPRO58; user ID=system; password=deb;";
conn = new OracleConnection(oracleb);
//conn.Open();
conn.Open();
String x3 = "google";
String x1 ;
String x2;
String s1 = "delete from temp";
OracleCommand comm = new OracleCommand(s1, conn);
comm.ExecuteNonQuery();


OracleCommand comm2 = new OracleCommand();
String s2 = "cv";
comm2.Connection = conn;
comm2.CommandText = s2;
comm2.CommandType = CommandType.StoredProcedure;
comm2.Parameters.Add("x", System.Data.OracleClient.OracleType.Number).Value = comboBox1.Text;
comm2.Parameters.Add("y", System.Data.OracleClient.OracleType.Number).Value = comboBox2.Text;
comm2.Parameters.Add("z", System.Data.OracleClient.OracleType.Number).Value = x3;
comm2.ExecuteNonQuery();

String s3 = "select * from temp";
OracleCommand comm3 = new OracleCommand(s3, conn);
OracleDataAdapter MyAdapter3 = new OracleDataAdapter();//adapter acts as interface btw database and dataset(which is collectio of tables)
MyAdapter3.SelectCommand = comm;
DataTable dTable3 = new DataTable();//datatable represents a single table in database
MyAdapter3.Fill(dTable3);
dataGridView1.DataSource = dTable3;
conn.Close();


My error is-



enter image description here



I am trying to run a procedure which has a cursor too.Therefore I am using 3 comm variables.But I am getting the above error.Therefore I was wondering how to solve it.



I have opened the connection in the starting of the function but still it is showing connection is closed.



edit-



my procedure name is cv



new error-
enter image description here



my procedure-



create or replace procedure cv(x in int,y in int,z in varchar)
as
cursor c
is
select email,collegename,cgpa,compname
from student_cv
where (cgpa>=x and yearsofexp>=y) and compname=z;
tem c%rowtype;
begin
open c;
loop
fetch c into tem;
exit when c%notfound;
insert into temp values(tem.email,tem.collegename,tem.cgpa,tem.compname);
end loop;
end;
/


line 59 is-



comm2.Parameters.Add("x", System.Data.OracleClient.OracleType.Number).Value = comboBox1.Text;






c# sql oracle visual-studio oracle11g






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 21:09

























asked Nov 9 at 20:01









ubuntu_noob

6611530




6611530












  • I see your comm and comm3 are using the conn but your comm2 and comm3 I dont see you setting the conn to use anywhere?
    – Brad
    Nov 9 at 20:07












  • Well spotted. That must be the culprit.
    – johey
    Nov 9 at 20:16










  • @Brad I did some changes and got new errors. line 59 is comm2.Parameters.Add("x", System.Data.OracleClient.OracleType.Number).Value = comboBox1.Text;
    – ubuntu_noob
    Nov 9 at 20:21










  • I dont think your using paramaters right, you need to put the paramater name in the text and set the value by using the paramanter set look here docs.microsoft.com/en-us/dotnet/api/…
    – Brad
    Nov 9 at 20:32










  • @Brad I have added the procedure
    – ubuntu_noob
    Nov 9 at 20:34


















  • I see your comm and comm3 are using the conn but your comm2 and comm3 I dont see you setting the conn to use anywhere?
    – Brad
    Nov 9 at 20:07












  • Well spotted. That must be the culprit.
    – johey
    Nov 9 at 20:16










  • @Brad I did some changes and got new errors. line 59 is comm2.Parameters.Add("x", System.Data.OracleClient.OracleType.Number).Value = comboBox1.Text;
    – ubuntu_noob
    Nov 9 at 20:21










  • I dont think your using paramaters right, you need to put the paramater name in the text and set the value by using the paramanter set look here docs.microsoft.com/en-us/dotnet/api/…
    – Brad
    Nov 9 at 20:32










  • @Brad I have added the procedure
    – ubuntu_noob
    Nov 9 at 20:34
















I see your comm and comm3 are using the conn but your comm2 and comm3 I dont see you setting the conn to use anywhere?
– Brad
Nov 9 at 20:07






I see your comm and comm3 are using the conn but your comm2 and comm3 I dont see you setting the conn to use anywhere?
– Brad
Nov 9 at 20:07














Well spotted. That must be the culprit.
– johey
Nov 9 at 20:16




Well spotted. That must be the culprit.
– johey
Nov 9 at 20:16












@Brad I did some changes and got new errors. line 59 is comm2.Parameters.Add("x", System.Data.OracleClient.OracleType.Number).Value = comboBox1.Text;
– ubuntu_noob
Nov 9 at 20:21




@Brad I did some changes and got new errors. line 59 is comm2.Parameters.Add("x", System.Data.OracleClient.OracleType.Number).Value = comboBox1.Text;
– ubuntu_noob
Nov 9 at 20:21












I dont think your using paramaters right, you need to put the paramater name in the text and set the value by using the paramanter set look here docs.microsoft.com/en-us/dotnet/api/…
– Brad
Nov 9 at 20:32




I dont think your using paramaters right, you need to put the paramater name in the text and set the value by using the paramanter set look here docs.microsoft.com/en-us/dotnet/api/…
– Brad
Nov 9 at 20:32












@Brad I have added the procedure
– ubuntu_noob
Nov 9 at 20:34




@Brad I have added the procedure
– ubuntu_noob
Nov 9 at 20:34

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232568%2fconnection-closed-when-using-cursor-and-procedure%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232568%2fconnection-closed-when-using-cursor-and-procedure%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()