C#、ASP.Net、SQL Server 2005、およびWindows Server 2008で構築された私の会社の内部プロジェクトの1つでは、誰かがログインしようとすると、ログインストアドプロシージャに無限の時間がかかります。しかし、データベースサーバーを再起動すると、問題は修正されます。これは毎日起こります。他のストアドプロシージャは正常に機能するため、これはデータベースのロードの問題ではない可能性があります。また、ストアドプロシージャ内でクエリを引き出すと、適切なタイミングで結果が得られます。データのフェッチとは別に、ストアドプロシージャには、ユーザーを一部のIPのみに制限するif条件があります。
何が問題なのかわかりません。誰かが問題を理解するのを手伝ってくれませんか。前もって感謝します。
これがストアドプロシージャです
ALTER PROCEDURE [dbo].[get_user]
@username varchar(50), @pwd varchar(50), @passcode varchar(50), @ipaddress varchar(15)
AS
BEGIN
IF(@ipaddress = 'aaa.aaa.aaa.aaa' OR @ipaddress = 'aaa.aaa.aaa.aaa' OR @ipaddress = 'aaa.aaa.aaa.aaa')
BEGIN
IF EXISTS(select up_id from tbl_user_profile (nolock) WHERE up_status='Y')
BEGIN
DECLARE @ri_date_time varchar(20)
SET @ri_date_time=convert(varchar(50),getdate(),120)
DECLARE @user_exists as int
Set @user_exists = 0
Set @user_exists = (Select count(*) from tbl_recent_items (nolock) where ri_user_name=@username)
IF @user_exists = 0
BEGIN
BEGIN TRAN
INSERT INTO tbl_recent_items (ri_user_name, ri_access_date_time) values (@username, @ri_date_time+'|'+@ipaddress+'^')
IF @@error=0 COMMIT TRAN ELSE ROLLBACK TRAN
END
ELSE
BEGIN
DECLARE @datetext varchar(max)
SET @datetext = (select isnull(ri_access_date_time,'') from tbl_recent_items(nolock) where ri_user_name=@username)
SET @datetext=@ri_date_time+'|'+@ipaddress+'^'+@datetext
BEGIN TRAN
UPDATE tbl_recent_items Set ri_access_date_time=@datetext where ri_user_name = @username
IF @@error=0 COMMIT TRAN ELSE ROLLBACK TRAN
END
END
SELECT CONVERT(varchar(4),up_id) as up_id,LTRIM(RTRIM(isnull(up_user_name,''))) as u_user_name,
ISNULL(up_password,'') as u_user_password,isnull(up_first_name,'') as up_first_name,
ISNULL(up_middle_name,'') as up_middle_name, isnull(up_last_name,'') as up_last_name,
ISNULL(up_branch_id,'') as up_branch_id, isnull(b_branch_id,'') as b_branch_id,
ISNULL(b_branch_name,'') as b_branch_name,isnull(up_mobile_phone,'') as up_mobile_phone,
--ISNULL(up_pager_phone,'') as up_pager_phone,
isnull(up_email,'') as up_email,
ISNULL(up_status,'') as u_status,
--isnull(up_job_posting_phone,'') as up_job_posting_phone,
-- ISNULL(up_level,'') as up_level,
isnull(up_trainee,'0') as up_trainee,
ISNULL(up_senior,'0') as up_senior, isnull(up_team_lead,'0') as up_team_lead, isnull(up_ist,'0')as up_ist, up_hyd_branch,
convert(varchar(10),up_password_date,102)as up_password_date
FROM tbl_user_profile (nolock)
LEFT OUTER JOIN tbl_branches (nolock) on up_branch_id = b_id where
up_user_name = @username and up_password =@pwd
END
IF EXISTS(select up_id from tbl_user_profile (nolock) WHERE up_user_name = @username and up_password = @pwd and up_passcode = @passcode and up_status='Y')
BEGIN
IF EXISTS(select up_id from tbl_user_profile (nolock) WHERE up_status='Y')
BEGIN
DECLARE @ri_date_time1 varchar(20)
SET @ri_date_time1=convert(varchar(50),getdate(),120)
DECLARE @user_exists1 as int
Set @user_exists1 = 0
Set @user_exists1 = (Select count(*) from tbl_recent_items (nolock) where ri_user_name=@username)
IF @user_exists1 = 0
BEGIN
BEGIN TRAN
INSERT INTO tbl_recent_items (ri_user_name, ri_access_date_time) values (@username, @ri_date_time1+'|'+@ipaddress+'^')
IF @@error=0 COMMIT TRAN ELSE ROLLBACK TRAN
END
ELSE
BEGIN
DECLARE @datetext1 varchar(max)
SET @datetext1 = (select isnull(ri_access_date_time,'') from tbl_recent_items(nolock) where ri_user_name=@username)
SET @datetext1=@ri_date_time1+'|'+@ipaddress+'^'+@datetext1
BEGIN TRAN
UPDATE tbl_recent_items Set ri_access_date_time=@datetext1 where ri_user_name = @username
IF @@error=0 COMMIT TRAN ELSE ROLLBACK TRAN
END
END
SELECT CONVERT(varchar(4),up_id) as up_id,LTRIM(RTRIM(isnull(up_user_name,''))) as u_user_name,
ISNULL(up_password,'') as u_user_password,isnull(up_first_name,'') as up_first_name,
ISNULL(up_middle_name,'') as up_middle_name, isnull(up_last_name,'') as up_last_name,
ISNULL(up_branch_id,'') as up_branch_id, isnull(b_branch_id,'') as b_branch_id,
ISNULL(b_branch_name,'') as b_branch_name,isnull(up_mobile_phone,'') as up_mobile_phone,
--ISNULL(up_pager_phone,'') as up_pager_phone,
isnull(up_email,'') as up_email,
ISNULL(up_status,'') as u_status,
--isnull(up_job_posting_phone,'') as up_job_posting_phone,
-- ISNULL(up_level,'') as up_level,
isnull(up_trainee,'0') as up_trainee,
ISNULL(up_senior,'0') as up_senior, isnull(up_team_lead,'0') as up_team_lead,isnull(up_ist,'0')as up_ist, up_hyd_branch,
convert(varchar(10),up_password_date,102)as up_password_date
FROM tbl_user_profile (nolock)
LEFT OUTER JOIN tbl_branches (nolock) on up_branch_id = b_id where
up_user_name = @username and up_password =@pwd
END
END