Showing posts with label appears. Show all posts
Showing posts with label appears. Show all posts

Tuesday, March 27, 2012

deleting old cursors

Hello. How can I delete an old cursor which appears when I execute the statement

select * from sys.dm_exec_cursors(0) ?

Thanks.

KILL session_id

...or alternatively if you can issue commands against the connection reported in the session_id column (for instance if the problem is with a SSMS connection that you have open) then you can issue:

CLOSE <cursor name>

DEALLOCATE <cursor name>

Chris

|||Thanks a lot.|||

Just to add that the first example I gave was really an 'emergency' measure. It would be advisable to track and fix the cause of the problem.

Chris

|||That was exactly what I was looking for, an emergency measure. I couldn't use close and deallocate. I forgot to mention that I am using SQL SERVER 2005. In a stored procedure I commented out a block together with close and deallocate for the respective cursor. The weird thing is that the procedure has only the declaration/definition of the cursor, otherwise there is no reference to it. I realized that it still exists when I received the error "cursor ... already exists". Thanks again for your answer.

deleting old cursors

Hello. How can I delete an old cursor which appears when I execute the statement

select * from sys.dm_exec_cursors(0) ?

Thanks.

KILL session_id

...or alternatively if you can issue commands against the connection reported in the session_id column (for instance if the problem is with a SSMS connection that you have open) then you can issue:

CLOSE <cursor name>

DEALLOCATE <cursor name>

Chris

|||Thanks a lot.|||

Just to add that the first example I gave was really an 'emergency' measure. It would be advisable to track and fix the cause of the problem.

Chris

|||That was exactly what I was looking for, an emergency measure. I couldn't use close and deallocate. I forgot to mention that I am using SQL SERVER 2005. In a stored procedure I commented out a block together with close and deallocate for the respective cursor. The weird thing is that the procedure has only the declaration/definition of the cursor, otherwise there is no reference to it. I realized that it still exists when I received the error "cursor ... already exists". Thanks again for your answer.

Thursday, March 22, 2012

Deleting dataset

Sorry if this post appears twice, but I couldn't see it posted last time.

Does anyone know an easy way (read not by going into the XML) of deleting a dataset?

Silly me! I missed the "Delete this dataset" button on the toolbar. Just ignore me and I'll go back to sleep!

Wednesday, March 7, 2012

Deleted "old" transaction logs = (no items) in EM. How to recover?

A mistake was made and "old" transaction logs (and old backups) were
deleted. It appears that a long living transaction was living in one of
those logs. Now the EP shows (no items). The DBs themselves are still
functioning OK, just the EP shell that's not working.

What's the proper resolution?

Thank you in advance,

FBCK(optimistck@.gmail.com) writes:
> A mistake was made and "old" transaction logs (and old backups) were
> deleted. It appears that a long living transaction was living in one of
> those logs. Now the EP shows (no items). The DBs themselves are still
> functioning OK, just the EP shell that's not working.
> What's the proper resolution?

EP?

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

Friday, February 24, 2012

Delete SP not firing?

I cannot get this event to fire. I am using TextBox9 to see if statements are processed and it never fills so it appears the Button4_Click never happens. Any ideas?

Thank you,

<asp:ButtonID="Button4"runat="server"OnClick="Button4_Click"Text="Delete Submission"/>

protected void Button4_Click(object sender, EventArgs e)
{
string CompanyDeleteID = TextBox10.Text;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["localhomeexpoConnectionString2"].ConnectionString);
SqlCommand cmd = new SqlCommand("DeleteSubmission", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@.C_ID", CompanyDeleteID);
TextBox9.Text ="SP completed";


}

PROCEDURE dbo.DeleteSubmission
@.C_ID int
AS
BEGIN
DELETE
FROM tblCompanyInfo_Submit
WHERE C_ID = @.C_ID

DELETE
FROM tblStoreStudioSubmit
WHERE C_ID = @.C_ID

DELETE
FROM tblContractorSubmit
WHERE C_ID = @.C_ID

RETURN
ENDWHERE CD_ID = @.C_ID
RETURN

Hi,

Is your event contained within a <script> tag in your aspx or in the code behind?

|||

Code Behind - however it is now firing once I removed Causes Validation from the Button4 control but the rows are not being removed. It looks like it processes and the Test textbox acknowledges the SP call is being made. Seems like it may be getting rolled back.

|||

Is your stored procedure working without error? You could test it through query window and see.

|||

I see this above. The bold section looks a little out of whack to me.

PROCEDURE dbo.DeleteSubmission
@.C_ID int
AS
BEGIN
DELETE
FROM tblCompanyInfo_Submit
WHERE C_ID = @.C_ID

DELETE
FROM tblStoreStudioSubmit
WHERE C_ID = @.C_ID

DELETE
FROM tblContractorSubmit
WHERE C_ID = @.C_ID

RETURN
ENDWHERE CD_ID = @.C_ID
RETURN

|||

Nevermind, I see. You are not actually executing your command. ie cmd.ExecuteNonQuery

|||

copy and paste error - actually ends at the END. The SP works in when called from directly in Visual Studio from the Server Explorer but does not successfully remove the rows when called from the page.

|||

Sorry, try this.

protected void Button4_Click(object sender, EventArgs e)
{
string CompanyDeleteID = TextBox10.Text;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["localhomeexpoConnectionString2"].ConnectionString);
SqlCommand cmd = new SqlCommand("DeleteSubmission", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@.C_ID", CompanyDeleteID);

cmd.ExecuteNonQuery();
TextBox9.Text ="SP completed";

}

|||

You are right. Tried the cmd.ExecuteNonQuery(); but it complained that a connection was not opened. So I installed a try, catch, finally block. Still looks like the SP is processing but the rows are either not being removed or are be rolled back.

string CompanyDeleteID = TextBox10.Text;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["localhomeexpoConnectionString2"].ConnectionString);
SqlCommand cmd = new SqlCommand("DeleteSubmission", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@.C_ID", CompanyDeleteID);
try
{
con.Open();
}
catch (SqlException exc)
{
TextBox4.Text += string.Format("Error: {0}<br/>", exc.Message);
}
finally
{
con.Close();
TextBox9.Text = "SP finished";
}

|||

I still don't see you executing the command. Try this.

string CompanyDeleteID = TextBox10.Text;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["localhomeexpoConnectionString2"].ConnectionString);
SqlCommand cmd = new SqlCommand("DeleteSubmission", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@.C_ID", CompanyDeleteID);
try
{
con.Open();

cmd.ExecuteNonQuery();
}
catch (SqlException exc)
{
TextBox4.Text += string.Format("Error: {0}<br/>", exc.Message);
}
finally
{
con.Close();
TextBox9.Text = "SP finished";
}

|||

I must be blind - thanks for your patience.

|||

No worries, I apologize for not seeing the two issues to begin with.

I'm glad I could help,

Best of Luck!