Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET
Want Query to Lock one process..
Wen we go to next month process first we want to lock previous month calculation by creating settings..
This should be for whole table we have set common lock procedure.
Need query for Sql2005
Posted 5-Mar-12 5:16am
Comments
Mark Nischalke at 5-Mar-12 10:38am
   
Your question is not clear
BobJanova at 5-Mar-12 11:24am
   
You can lock tables within a single transaction trivially. I think you mean permanently locking a whole table as a read only archive, in which case you should remove the UPDATE and DELETE (and ALTER etc) privileges from the application user on that table.
Charuroopa at 5-Mar-12 11:33am
   
not asking for permanent locking..
if we want to calculate next month calculation first we have to lock previous once right? for that i need query..
and also we want to lock the financial year while we move to next year process..
Whether we want to maintain one separate table for this process or how we have to proceed it further..
Charuroopa at 6-Mar-12 1:06am
   
What i m doing is payroll project...
For that i am asking..
i hope now u wil come to know for what i am asking for...
Charuroopa at 7-Mar-12 1:08am
   
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Security;
 
namespace lockprocedure
{
public partial class _Default : System.Web.UI.Page
{
 
SqlDataReader reader;
SqlConnection conn;
SqlCommand cmd;
protected void Page_Load(object sender, EventArgs e)
{
 
}
 
protected void Button1_Click(object sender, EventArgs e)
{
string connectionString="Data Source=SNSWAMY\\SQLEXPRESS;Initial Catalog=payroll;Persist Security Info=True;User ID=******;Password=*********";
conn = new SqlConnection(connectionString);
string updateSql = "update lock_table set key_value=1 where sal_date='2012-02-25 00:00:00.000'";
cmd = new SqlCommand(updateSql, conn);


try
{
conn.Open();
cmd.ExecuteNonQuery();

}
catch (Exception)
{
 
}
finally
{
conn.Close();
}
MessageBox("Locked the previous month calculation");
}
private void MessageBox(string message)
{
if (!string.IsNullOrEmpty(message))
{
Response.Write("<script type=\'text/javascript' language=\'javascript\'>");
Response.Write("alert('" + message + "');");
Response.Write("</script>");
}
}

 
protected void Button2_Click(object sender, EventArgs e)
{
int key_value;
string connectionstring="Data Source=SNSWAMY\\SQLEXPRESS;Initial Catalog=payroll;Persist Security Info=True;User ID=******;Password=******";
conn = new SqlConnection(connectionstring);
conn.Open();
// string updateSql = "update salary set key_value=1 where process_datetime='2012-02-25 00:00:00.000'";
SqlCommand cmd = new SqlCommand(("select key_value from lock_table where sal_date='2012-02-25 00:00:00.000' "), conn);
// cmd = new SqlCommand(updateSql, conn);
cmd.Connection = conn;
 

reader = cmd.ExecuteReader();

//reader.Read();
 
/*if (reader.HasRows)
{
}*/
while (reader.Read())
{
// key_value = reader.GetOrdinal("key_value");
reader.Read();
reader["key_value"].ToString();
//key_value = reader.GetOrdinal("key_value");
//Console.WriteLine(reader.GetInt32(1));
/* if (key_value == 0)
{
MessageBox("Lock the previous Month Calculation");
}
else
{
MessageBox("Can proceed further");
}
reader.Close();*/
 
}
 
key_value = reader.GetOrdinal("key_value");
// int key_value =reader.GetInt32(reader.GetOrdinal("key_value"));

if (key_value == 0)
{
MessageBox("Lock the previous Month Calculation");
}
else
{
MessageBox("Can proceed further");
}
reader.Close();
 
}

}
}
 
-------------------------------------------------------------------------------
This is my code for lock procedure.. In this i am getting an error invalid attempt to read when no data is present. c# and also reader is not working properly because after i locked the previous month calculation again it is asking to lock

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

This is ENTIRELY dependant on your business requirements, procedures, and your database design. What you do is entirely up to you. You don't NEED to "lock" anything unless your design requires it, depending on what your definition of "lock" is.
 
It may be as simple as taking the records from the production tables and moving them to archive tables of some kind. I, and nobody here, has any idea of what your requirements and design are, so it's impossible to say exactly.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 555
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 359
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 5 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100