473,799 Members | 3,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Database connection problem.

2 New Member
Below is the following procedure where I am facing the problem, the work of the below procedure is to update the database.

query result:sp_helpt ext bProjectUpdate

Text
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


CREATE PROCEDURE bProjectUpdate
@CallingMemberI D udtKeyAlias, --DefCallingMembe rID, --DefID
@KeyType udtKeyType,
@ForceValidatio n int, --DefForceValidat ion --DefTrueFalse --0=false, 1=true
@ProjectID udtUniqueKey,
@Reference udtReference, --DefReference
@Name udtName, --DefName
@StartDate udtLongDate,
@EndDate udtLongDate,
@ProjectStatusK ey udtKeyAlias,
@ParentKey udtKeyAlias, --DefID, --DefReference, --DefKey
@OrganizationKe y udtKeyAlias --DefID, --DefReference, --DefKey

AS

set nocount on

declare
@RetCode int,
@ProcName varchar(100),
@HistoryText udtHistoryText,
@PhaseID udtUniqueKey, --DefID
@ParentProjectI D udtUniqueKey, --DefID
@ProjectTypeID udtSystemCodeID ,--DefProjectTypeI D, --DefSystemCodeID
@ProjectStatusI D udtSystemCodeID ,
@OrganizationID udtUniqueKey, --DefID
@ValidCallingMe mberID udtUniqueKey, --DefMemberID, --DefID
@ValidationStri ng varchar(255), --DefValidationSt ring
@ErrorMessage varchar(255), --DefErrorMessage
@nExternalID udtExternalID, --Int version of ExternalID --DefExternalID
@nExternalTypeI D int, --Int version of ExternalTypeID --DefExternalType ID
@Entity varchar(255),
@CurrReference udtReference,
@CurrName udtName,
@CurrStartDate udtLongDate,
@CurrEndDate udtLongDate,
@CurrParentID udtUniqueKey,
@CurrProjectSta tusID udtSystemCodeID ,
@CurrOrganizati onID udtUniqueKey

--Initialisations
select @ValidationStri ng = '',
@RetCode = 0,
@ProcName = 'bProjectUpdate '


-- CallingMember must a valid Member
exec @RetCode = dMemberValidate @CallingMemberI D, 1, @ProcName
if @RetCode <> 0
return @RetCode


exec @RetCode = dKeyTypeValidat e @CallingMemberI D, @KeyType, @ProcName
if @RetCode <> 0
return @RetCode

-- Verify that the Project exists
if not exists (select ProjectID from Project where ProjectID = @ProjectID)
begin
exec @RetCode = ErrorMessageGet @CallingMemberI D, 1023, @ProcName
return @RetCode
end
else
begin
select @CurrReference = Reference,
@CurrName = Name,
@CurrStartDate = StartDate,
@CurrEndDate = EndDate,
@CurrProjectSta tusID = ProjectStatusID ,
@ProjectTypeID = ProjectTypeID,
@CurrParentID = ParentProjectID ,
@CurrOrganizati onID = OrganizationID
from Project
where ProjectID = @ProjectID
end

-- Verify that the new Reference Code does not clash with any existing Project in this organization
if exists (select ProjectID from Project where ProjectID <> @ProjectID and Reference=@Refe rence and ProjectTypeID=@ ProjectTypeID and OrganizationID= @OrganizationID )
begin
exec @RetCode = ErrorMessageGet @CallingMemberI D, 1032, @ProcName
return @RetCode
end

if isnull(@ParentK ey, '') <> ''
begin

if @KeyType = 1
--Validate that the Parent Project is valid
select @ParentProjectI D = ProjectID
from Project
where ProjectID = @ParentKey
and ProjectTypeID = 1
else
select @ParentProjectI D = ProjectID
from Project
where Reference = @ParentKey
and ProjectTypeID = 1


if @ParentProjectI D is null
begin
--Invalid Parent Project Key
execute @RetCode = ErrorMessageGet @CallingMemberI D, 1027, @ProcName
return @RetCode
end
end
else
select @ParentProjectI D = ParentProjectID from Project where ProjectID = @ProjectID


--OrganizationKey
-- Organization can either be passed in.
-- To Do (in which case it should be validated against the set that this calling member
-- is allowed to add employees for.
-- OR
-- It can be defaulted from the CallingMember's Organization.
if @OrganizationKe y <> ''
if @KeyType = 1
select @OrganizationID = OrganizationID from Organization where OrganizationID = @OrganizationKe y
else
select @OrganizationID = OrganizationID from Organization where Reference = @OrganizationKe y
else
select @OrganizationID = OrganizationID from Organization_Me mber where MemberID = @CallingMemberI D

if @OrganizationID is null
begin
-- No organization found with that reference
execute @RetCode = ErrorMessageGet @CallingMemberI D, 1019, @ProcName
return @RetCode
end


-- Validate the Project Status
exec @RetCode = dProjectStatusV alidateKey @CallingMemberI D, @KeyType, @ProcName, @ProjectStatusK ey, @ProjectStatusI D output, @ErrorMessage output
if @ProjectStatusI D = -1
begin
exec @RetCode = ErrorMessageGet @CallingMemberI D, @RetCode, @ProcName
return @RetCode
end

BEGIN TRAN


--Process Project
if @ProjectTypeID = 1
begin
select @Entity = 'Project'
update Project
set Reference = @Reference,
Name = @Name,
StartDate = @StartDate,
EndDate = @EndDate,
ProjectStatusID = @ProjectStatusI D,
ParentProjectID = @ParentProjectI D,
OrganizationID = @OrganizationID
where ProjectID = @ProjectID

select @PhaseID = NULL
select @PhaseID = ProjectID from Project where ParentProjectID = @ProjectID and ProjectTypeID = 2
-- Also update the default Phase - (with ProjectTypeID= 2 but same reference and name as the Project)
if @PhaseID is not null
begin
update Project
set Reference = @Reference,
Name = @Name,
StartDate = @StartDate,
EndDate = @EndDate,
ProjectStatusID = @ProjectStatusI D,
OrganizationID = @OrganizationID
where ProjectID = @PhaseID
end
end
--Otherwise the Phase
else
begin
select @Entity = 'Phase'
select @PhaseID = @ProjectID
update Project
set Reference = @Reference,
Name = @Name,
StartDate = @StartDate,
EndDate = @EndDate,
ProjectStatusID = @ProjectStatusI D,
ParentProjectID = @ParentProjectI D,
OrganizationID = @OrganizationID
where ProjectID = @PhaseID

-- TBD - 01.DEC.2000 - PBO Issue #286 - Supplemental - Per CCN, this should
-- also set the Project's RecordStatus to 1 (Inactive) so I added the extra
-- set statement.
--Need to mark the default Phases as deleted once someone adds a new one.
update Project set ProjectStatusID = 2, RecordStatus = 1 where ParentProjectID = @ParentProjectI D and ProjectTypeID = 2

-- TBD - 01.DEC.2000 - PBO Issue #286 - Supplemental - Per CCN, we should also
-- delete any rows in the Employee_Projec t table that reference any Project
-- table rows that have been tagged as inactive by the above statement.
delete ep
from employee_projec t as ep
join project as p on p.ProjectID = ep.ProjectID
and p.RecordStatus <> 0
and p.ParentProject ID = @ParentProjectI D
and p.ProjectTypeID = 2

end


select @ProjectID, @PhaseID, @Reference, @Name, @StartDate, @EndDate, @ProjectStatusI D

--Write an action history record
select @HistoryText = ''
select @HistoryText = isnull(@History Text + '<' + @Entity + 'Update>', '<NULL>')
if @ProjectTypeID = 1
select @HistoryText = isnull(@History Text + '<' + @Entity+ 'ID>' + cast(@ProjectID as varchar(50)) + '</' + @Entity+ 'ID>', '<NULL>')
else
select @HistoryText = isnull(@History Text + '<' + @Entity+ 'ID>' + cast(@PhaseID as varchar(50)) + '</' + @Entity+ 'ID>', 'NULL')
if @Reference <> @CurrReference
select @HistoryText = isnull(@History Text + '<Reference><Fr omReference>' + @CurrReference + '</FromReference>< ToReference>' + @Reference + '</ToReference></Reference>', '<NULL>')
if @Name <> @CurrName
select @HistoryText = isnull(@History Text + '<Name><FromNam e>' + @CurrName + '</FromName><ToNam e>' + @Name + '</ToName></Name>', '<NULL>')
if @StartDate <> @CurrStartDate
select @HistoryText = isnull(@History Text + '<StartDate><Fr omStartDate>' + cast(@CurrStart Date as varchar(50)) + '</FromStartDate>< ToStartDate>' + cast(@StartDate as varchar(50)) + '</ToStartDate></StartDate>', '<NULL>')
if @EndDate <> @CurrEndDate
select @HistoryText = isnull(@History Text + '<EndDate><From EndDate>' + cast(@CurrEndDa te as varchar(50)) + '</FromEndDate><To EndDate>' + cast(@EndDate as varchar(50)) + '</ToEndDate></EndDate>', '<NULL>')
if @ProjectStatusI D <> @CurrProjectSta tusID
select @HistoryText = isnull(@History Text + '<ProjectStatus ID><FromProject StatusID>' + cast(@CurrProje ctStatusID as varchar(50)) + '</FromProjectStat usID><ToProject StatusID>' + cast(@ProjectSt atusID as varchar(50)) + '</ToProjectStatus ID></ProjectStatusI
D>', '<NULL>')
if @OrganizationID <> @CurrOrganizati onID
select @HistoryText = isnull(@History Text + '<OrganizationI D><FromOrganiza tionID>' + cast(@CurrOrgan izationID as varchar(50)) + '</FromOrganizatio nID><ToOrganiza tionID>' + cast(@Organizat ionID as varchar(50)) + '</ToOrganizationI D></OrganizationID> ', '<N
ULL>')
if @ParentProjectI D <> @CurrParentID
select @HistoryText = isnull(@History Text + '<ParentProject ID><FromParentP rojectID>' + cast(@CurrParen tID as varchar(50)) + '</FromParentProje ctID><ToParentP rojectID>' + cast(@ParentPro jectID as varchar(50)) + '</ToParentProject ID></ParentProjectID >', '<
NULL>')
select @HistoryText = isnull(@History Text + '</' + @Entity+ 'Update>', '<NULL>')

if @ProjectTypeID = 1
exec bActionHistoryA dd @CallingMemberI D, 2, 'pr', @ProjectID,'upd ate', @HistoryText
else
exec bActionHistoryA dd @CallingMemberI D, 2, 'ph', @PhaseID,'updat e', @HistoryText

COMMIT TRAN
Sep 18 '06 #1
0 1513

Sign in to post your reply or Sign up for a free account.

Similar topics

14
4826
by: Nick Gilbert | last post by:
Hi, I have an asp.net application which runs from a CD-ROM using Cassini. As such, it is single user only. The application connects to an Access database when it is loaded, and keeps the same connection open all the time (as it's single user, this shouldn't be a problem). There is logic in the code to ensure that the connection is
7
2242
by: News | last post by:
Hello, I have to build a program with the future in mind and I need a bit of guidance from a guru or two. My program will start as a multi-user Windows Application built with VB.Net and using an Access 2002 database backend. The future will require that 1. The database be switched with minimal effort to SQL Server and 2. A Web Application be added to allow web access to reports generated from the database. At this time, there is no...
2
15318
by: Ron St-Pierre | last post by:
We're developing a java app and are using postgres as the database. On our dev server I started the app, closed it, but the java process was still open so I killed it, which caused the above error. I've had to do this in the past but have not had this happen before. I've searched the archives and found a message/reply from Andrew Sullivan about this which implies that it may be more a file system problem. We're using postgresql 7.4.1 on a...
10
9621
by: mjf | last post by:
Hello, We made a backup image file for a database on one machine (A), and we restored the database on another machine (B), using the backup image file. Everything went fine. But when we try to connect to the database on B, it's taking forever (about 1 minute) if it's the first connection to the database. Any following connections have no problem. If we close all the connections, and do a connection again, it will take about 1 minute...
3
10298
by: Martin B | last post by:
Hallo! I'm working with C# .NET 2.0, implementing Client/Server Applications which are connecting via Network to SQL-Server or Oracle Databases. To stay independent from the underlaying Database I use System.Data.Common.DBConnection and .DBCommand. How can I keep aware from connection losses (network not availeable, db-server not available...)? Are there any strategies to detect this broken connections, and how can I
5
1648
by: Sam | last post by:
Hi all, I have a process which first pulls one time all application IDs from a database and stores them in a table(this process works fine everytime). I then loop through the table, one at a time, and use application id to pull details info and process it. For example, if I have 500 records in my table, then I would have to open database 500 times. Also between processing each record, my process sleep 3 seconds. The problem is that...
18
9156
by: surfrat_ | last post by:
Hi, I am having the following problems in getting Microsoft Visual Studio 2005 Professional to link to an Access .mdb database. Please help me to sort this out. Problem 1: The Microsoft page "How to: Connect to Data in an Access Database"
5
3401
by: Usman Jamil | last post by:
Hi I've a class that creates a connection to a database, gets and loop on a dataset given a query and then close the connection. When I use netstat viewer to see if there is any connection open left, I always see that there are 2 connections open and in "ESTABLISHED" state. Here is the piece of code that I'm using, please tell where I'm doing it wrong. Since this class is being used at many placed in my actual web based application that...
8
2839
by: BD | last post by:
I am developing C# win form app to work with remote database on SQL Server 2005. Problem scenario is as follows: 1. a form is open that has downloaded dataset to local cache 2. computer is put into stand-by or hibernation 3. later, computer is brought out of stand-by or hibernation 4. when trying to save or close form, SQL exception comes up (remote system closed conn) I know this relates to connection pooling, but I am having a...
39
5873
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f ISO-8859-1 -t UTF-8 mydb.sql mydb_utf8.sql mysqlCREATE DATABASE mydb_utf8 CHARACTER SET utf8 COLLATE utf8_general_ci;
0
10260
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10243
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.